Reputation: 1345
In a web page, I have input elements, such as:
<input type="checkbox" data-initialstate="False">
The initialstate
property is set when the page is built server-side.
In order to display a list of all checkboxes that were disabled, and are now disabled, I would like to make a jQuery selection, such as:
$(input and value = true and data-initialstate = false)
But I can't find the correct syntax. What is the correct way to do this?
Upvotes: 1
Views: 30
Reputation: 337656
Presumably by 'value = true' you mean checked checboxes. If so, to achieve this you can use the :checked
and attribute selectors. Try this:
var $checkboxes = $('input:checkbox:checked[data-initialstate="False"]');
Note though, that this will not work if the data
attribute is modified during the page lifetime. In that case you would need to use filter()
, like this:
var $checkboxes = $('input:checkbox:checked').filter(function() {
return !$(this).data('initialstate');
});
Upvotes: 2