what is the difference between getelementsbytagname and getelementsbyname in javascript -
i came across these 2 methods dom elements retrieval in douglas crockford presentation couldn't understand difference between these two.
document.getelementsbytagname() document.getelementsbyname()
can please explain me.
the link video http://www.youtube.com/watch?v=fv9qt9joc0m
suppose have html :
<input name="test" class="cssclassname">
you'd got with
document.getelementsbytagname('input')
or
document.getelementsbyname('test')
or
document.getelementsbyclassname('cssclassname')
also, can call getelementsbytagname
on elements other document. example following allowed,
document.getelementsbyid('foo').getelementsbytagname('bar')
but getelementsbyname
can called on document
.
notes :
- javascript case sensitive, can't write functions did in question
- those functions don't return element live nodelist, you'll have iterate on result or take first 1 if you're sure it's :
document.getelementsbytagname('input')[0]
- the mdn documentation javascript methods. should read getelementsbytagname , getelementsbyname.
Comments
Post a Comment