Im sure this is something really basic, but I'm tierd:p
I have a set up like this:
<div id='hi'>
<span id='hi2'>
</span>
</div>
i need to access the span, but after dictating the div first (not tag name specific) this is as i have many "spans" with the same id but within "divs". I tried something like this:
var 1 = document.getelementbyid('hi');
var 2 = var1.getelementbyid('hi2');
it didnt take:p
thanks!
getelementbyid troublesy
Started by influct, Dec 03 2007 06:56 PM
6 replies to this topic
#1
Posted 03 December 2007 - 06:56 PM
#2
Posted 03 December 2007 - 07:04 PM
var 1 = document.getElementById('hi');
javascript is case sensitive ;-)
javascript is case sensitive ;-)
#3
Posted 03 December 2007 - 07:10 PM
ah sorry, should have specified my code was a bit rough, the real thing has the correct case:)
thanks anyway.
thanks anyway.
#4
Posted 03 December 2007 - 07:13 PM
Quote
i have many "spans" with the same id
If you want everything to have a similar attribute in common, make it a class, not an id.
Since i also believe getElementById is document specific, you could run a loop through the div till you run into something with a matching id... but of course, i remember jerry-rigging something like this myself (using your method) and it worked fine.
#5
Posted 03 December 2007 - 07:25 PM
i understand that and thanks, but is there not a way to search inside a predefined area for the matching id? in this case i want to search for the id hi2 within the area hi1, not the entire document. although i trust your opinion so will assume as you said this is not feasible. would you mind posting some sample code as for workarounds?
Edit: no wait thats something else im thinking of:(
thanks!
Edit: no wait thats something else im thinking of:(
thanks!
Edited by influct, 03 December 2007 - 07:58 PM.
#6
Posted 03 December 2007 - 08:01 PM
I have resolved to simply do it by name. why i did not do this before i can't begin to imagine, thanks for correcting me over my misconceptions and setting me on the right path!
#7
Posted 05 December 2007 - 07:38 PM
Even W3C will pull you on your duplicate IDs just for future reference
!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
