Pear Pear - 1 month ago 7
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
arguments
for this but what if I want to do it like the method above? Thanks!
Also no jQuery please

Answer

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']");
}