TypeError getElementsByTagName is not a function

I am having trouble getting this problem. Basically the error message I get in my console:

TypeError: $(...).getElementsByTagName is not a function

When I click on a line, it appears here:

var inputs = $('directoryresults').getElementsByTagName('input');

I'm not sure why this is happening, as I included jQueryin the title of the page itself:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>

Does anyone have any ideas what might cause this?

+4
source share
4 answers

Does anyone have any ideas what might cause this?

The object returned by the jQuery constructor has no method .getElementsByTagName().


$('selector')returns a jQuery object. .getElementsByTagName()is a native JavaScript method of DOM elements.

Search for elements with a specific tag using the jQuery object you have:

var inputs = $('directoryresults input');
// OR
var inputs = $('directoryresults').find('input');

node, .getElementsByTagName() ( , , , .getElementsByTagName() HTMLCollection):

var inputs = $('directoryresults input').get();

: directoryresults, , , DOM.

+6

getElementsByTagName - , Element Document.

$('directoryresults') jQuery ( <directoryresult>... , HTML-).

getElementsByTagName, jQuery:

$('directoryresults')[0].getElementsByTagName

jQuery ( , ), , , [0] for.

, find:

$('directoryresults').find('input')

... :

$('directoryresults input')

, directoryresults HTML-. , . # , .

+3

DOM API, jQuery API sintax:

it document.getElementsByTagName('input');

+2

, directoryresults -

, ,


If you use jQuery like TagName, this is:

var inputs = $('input');

if you want to put values ​​in a div

$.each(inputs, function(){
    $('div').append( $(this).val() );
});
0
source

All Articles