I'm passing a var el
into a function. el
contains previously grabbed element (using getElementById) and when I console.log el
in the function I get the following:
The problem comes in when I try to grab an element inside of the el
using:
el.getElementsByName('fname');
I get the error:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'getElementsByName'
I'm passing a var el
into a function. el
contains previously grabbed element (using getElementById) and when I console.log el
in the function I get the following:
The problem comes in when I try to grab an element inside of the el
using:
el.getElementsByName('fname');
I get the error:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'getElementsByName'
Share
Improve this question
asked Feb 12, 2013 at 22:22
FluidbyteFluidbyte
5,21010 gold badges49 silver badges79 bronze badges
2
|
1 Answer
Reset to default 17The getElementsByName()
API is at the document
object level. It's not an HTMLElement method.
You could use querySelectorAll()
instead:
var fnames = el.querySelectorAll('[name=fname]');
It's not supported in older browsers however.
getElementsByName
is not a method of that object. Is el from a library like jQuery? I think you wantdocument.getElementsByName
without knowing whatel
is. – Leeish Commented Feb 12, 2013 at 22:23