Pear Pear - 4 months ago 46
Javascript Question

Javascript getElementsByName not working?

I have a function like this

function f(el){
var a = el.getElementsByName("name");

but I am getting "el.getElementsByName is not a function" error
I know that I can use
for this but what if I want to do it like the method above? Thanks!
Also no jQuery please


From your comment, you are using that function on nodes, and this is a document function, not a DOMnode function.

However, you could use this one:

function f(el){
   var a = el.querySelector("[name='name']");