This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes getElementById  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "getElementById  " Watch "getElementById  " New topic


ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 374
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


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

please help explain. thanks
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60774

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: getElementById
Similar Threads
Showing Hiding <s:div> tag in Struts2
showing fields dynamically
web page printing
Scrollbars, simultaneously
How to make colored variable length bars in FF?