Reputation: 12695
I have a table
tag on my page. I'm adding dynamically a new set of rows, where some of them can contain a <button class="btn btn-primary"></button>
tag. I'm wondering, how to check the information via JQuery, if that table contains any rows with that button ?
Upvotes: 0
Views: 837
Reputation: 337560
You can use length
to check the existence of an element. Try this:
var buttonExists = $("table .btn-primary").length != 0;
Upvotes: 2
Reputation: 1915
Just try:
var buttons = $table.find('.btn.btn-primary');
var buttonExists = buttons.length > 0;
Table has to be a jQuery object containing your table.
Upvotes: 3