dapperwaterbuffalo
dapperwaterbuffalo

Reputation: 2748

count elements after DOM change

so currently using ajax with JQuery .post to return a form populate with some values. What I am trying to do is basically identify if the content contains checkboxes using:

var count = $('#form').find('checkbox').length;
alert(count);

however even when it does contain checkboxes the output is 0. So do I have the syntax wrong or is it something to do with the fact the checkboxes weren't in the original DOM?

many thanks,

Upvotes: 1

Views: 141

Answers (1)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196002

There is no tag checkbox, you will need to use the :checkbox docs selector

$('#form').find(':checkbox').length;

or the more verbose

$('#form').find('input[type="checkbox"]').length;

Upvotes: 5

Related Questions