Pear Pear - 1 year ago 116
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

Answer Source

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']");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download