wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes difference between getElementById and getElementByName? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "difference between getElementById and getElementByName?" Watch "difference between getElementById and getElementByName?" New topic
Author

difference between getElementById and getElementByName?

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
JavaScript - Which are the difference between getElementById and getElementByName?

André AS
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no getElementByName. There is getElementsByName. Guessing typo there.

getElementById gets an element via an id. getElementsByName returns an Array of elements by their name.

Some horrible browsers will use name if it can not find an id for getElementById and those browsers should be uninstalled and bytes burnt to a crisp.

Eric
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
anyway getElementById is more use than other right?

thanks,
André AS
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

André Asantos wrote:anyway getElementById is more use than other right?

In my opinion, yes.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

Yes, identifying elements by id is much preferred unless you have a really good reason to need to use the name (which does not have to be unique).
 
wood burning stoves
 
subject: difference between getElementById and getElementByName?