473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

several div with same dom id

Hello,

Is it possible to have a div component, that i repeat several time
on an html page : all those occurences of the div with the same dom
id.

thanx.

Mar 24 '07 #1
5 1686
On 24 Mar, 14:23, "Jean-Sébastien" <jeansebastien....@gmail.com>
wrote:
Hello,

Is it possible to have a div component, that i repeat several time
on an html page : all those occurences of the div with the same dom
id.

thanx.
yes, but you will have a hard time referencing them, id's should be
unique, obviously!
switch to a classname instead, and style accordingly and then
reference the divs by their classname, unless you need to reference by
ID from some reason in which case you component should give them
unique ids.

Mar 24 '07 #2
ASM
Jean-Sébastien a écrit :
Hello,

Is it possible to have a div component, that i repeat several time
on an html page : all those occurences of the div with the same dom
id.
Tout est possible ! Le brouteur ne sera pas géné.

No you can't :
- not allowed by standards
- not usable : how to reach this or that div ?

If you want to copy a div and use this copy, you have to set it a new id
before to insert it

var idx = 0;
function addDiv() {
var d = document.getElementById('template').cloneNode(true );
d.id += '_'+idx;
document.body.appendChild(d);
idx++;
}

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Mar 24 '07 #3
On Mar 24, 3:44 pm, ASM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
Jean-Sébastien a écrit :
Hello,
Is it possible to have a div component, that i repeat several time
on an html page : all those occurences of the div with the same dom
id.

Tout est possible ! Le brouteur ne sera pas géné.

No you can't :
- not allowed by standards
- not usable : how to reach this or that div ?

If you want to copy a div and use this copy, you have to set it a new id
before to insert it

var idx = 0;
function addDiv() {
var d = document.getElementById('template').cloneNode(true );
d.id += '_'+idx;
document.body.appendChild(d);
idx++;

}

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
merci
thank you
:)

Mar 24 '07 #4
"Jean-Sébastien" <je***************@gmail.comwrote:
>Hello,

Is it possible to have a div component, that i repeat several time
on an html page : all those occurences of the div with the same dom
id.
Yes, but you won't be able to access them from script. The DOM assumes
that IDs are unique within a page. If there are more than one element
with the same ID, document.getElementById() will return the first
element with the requested ID. In order to get all of the DIVs, you'd
have to call document.getElementsByTagName, and cycle through the
array that function returns.

--
Tim Slattery
Sl********@bls.gov
http://members.cox.net/slatteryt
Mar 26 '07 #5
Tim Slattery said the following on 3/26/2007 9:49 AM:
"Jean-Sébastien" <je***************@gmail.comwrote:
>Hello,

Is it possible to have a div component, that i repeat several time
on an html page : all those occurences of the div with the same dom
id.

Yes, but you won't be able to access them from script.
As well as it being invalid HTML. The ID attribute *must* be unique in
the document.
The DOM assumes that IDs are unique within a page.
Yet the HTML specs require it to be unique within a page.
If there are more than one element with the same ID, document.getElementById()
will return the first element with the requested ID.
Although it is not required to. It could return any of them and nobody
could say it was wrong.
In order to get all of the DIVs, you'd have to call
document.getElementsByTagName, and cycle through the
array that function returns.
The "array" or the "collection"? It would return a collection, not an
array. Try sorting the results....
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: intl04 | last post by:
I was told by an instructor of Oracle SQL that an MS Access database cannot be used to have several people enter records at about the same time, that the database will "freeze up" as a result -...
4
by: Malkocoglu | last post by:
In the good old days , i had a class that had 30 functions (let's say) There was a single include(*.H) file and i could have several implementation(*.CPP) files The reason for doing this is to...
27
by: HKSHK | last post by:
Hello, I have this problem: I wrote some DLLs with VB.Net 2003 which I use with my programs. But I want to avoid that I have to go down to "DLL hell" and to copy all used dlls into each program...
1
by: kristof.bonnast | last post by:
Hi all, I'm have a console app which is called by a thirth party system over 20000 times a day. This console app links to a webservice on another server to capture information. This works fine...
3
by: ton | last post by:
Hi, I'm using AJAXPRO this works very well. What I want to do is to add new page elements at my web site without using a postback. And I do not mean listitems but a complete dialog. Let me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.