File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes getElementById  Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "getElementById  " Watch "getElementById  " New topic
Author

getElementById

ben oliver
Ranch Hand

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

Joined: Jan 10, 2002
Posts: 56178
    
  13

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.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: getElementById
 
Similar Threads
How to make colored variable length bars in FF?
web page printing
Scrollbars, simultaneously
showing fields dynamically
Showing Hiding <s:div> tag in Struts2