James
James

Reputation: 1485

Select jquery object by data attribute

My html fragment goes something like

<button data-file="day">Day</button>
<button data-file="night">Night</button> 

and I'm trying to do the following in Jquery

var $button = $('button');
$button.data('file' , 'day').attr('disabled', 'disabled');

So make jQuery objects of all buttons then disable the button with data attribute day

Upvotes: 3

Views: 167

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388416

You need to use the attribute selector and need to use .prop() to set the disabled state

var $button = $('button[data-file="day"]');
$button.prop('disabled' , true);

Update

var $button = $('button');
$button.filter('[data-file="day"]').prop('disabled' , true);

Upvotes: 4

Related Questions