David B
David B

Reputation: 3571

Getting all <input> inside the document

How can I display in my console the list of all <input> tags inside the HTML?

I've tried to use $('input'), $(':input'), or even $('tbody input') all of those commands returns jQuery.fn.jQuery.init[<number>].

Anyways, I am using Google Chrome. Yet I think it wouldn't affect other browsers, which of course IE is an exemption.

Upvotes: 1

Views: 72

Answers (3)

Felix Kling
Felix Kling

Reputation: 816442

$('input') is the correct approach. $(...) returns a jQuery object and jQuery.fn.jQuery.init[<number>] is the console's representation of such an object.

It means that you have an array like object, constructed by the function jQuery.fn.jQuery.init, with <number> elements.

That's normal, your code works fine (at least in this regard), $('input') is the correct approach.


Of course you should make to select the elements after the document is loaded, which is all explained the jQuery tutorial.

Upvotes: 1

Milind Anantwar
Milind Anantwar

Reputation: 82241

wrap the code in documnet ready to ensure that dom is loaded.also you dont even need jquery for that:

var allinput = document.getElementsByTagName('input');

Upvotes: 0

BenM
BenM

Reputation: 53198

Place a call inside your DOMReady event as follows:

$(function() {  
    var inputs = $('input');
    console.log(inputs);
});

Upvotes: 0

Related Questions