Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getElementById

 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If my html has nested structure like



Assuming there is only ONE elemet whose id is called "myinput" (no ambiguity), does

document.getElementById("myinput") work ?

or should we do

document.getElementById("div1").getElementById("div2").getElementById("myinput")


I found sometimes it works using the first one but sometimes it doesn't.

please help explain. thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ben oliver wrote:
Assuming there is only ONE elemet whose id is called "myinput" (no ambiguity),

In any document all id values need to be unique. If they are not, the document is invalid and all bets are off.

does document.getElementById("myinput") work ?

Yes. For valid documents.

or should we do

Never.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic