Pear Pear - 5 months ago 48
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']");