Pradeep
Pradeep

Reputation: 103

How to select a checkbox using an attribute value?

Given this checkbox:

<input data-index="7" data-name="Sector-108" type="checkbox">

how do I uncheck this checkbox based on the data-name attribute selector?

Upvotes: 0

Views: 3970

Answers (3)

Dipesh Parmar
Dipesh Parmar

Reputation: 27364

You can use it as below.

$('input').hasAttr('data-name').attr('checked','checked');

Upvotes: 0

Barmar
Barmar

Reputation: 781280

$('input[data-name=Sector-108]).removeProp('checked');

Upvotes: 0

Adil
Adil

Reputation: 148140

You can use attribute selector

$('[data-name=Sector-108]').prop('checked',true);

You can use attribute selector starts with wild card to get all the elements having name like Sector-

$('[data-name^=Sector-]').prop('checked',false);

Upvotes: 1

Related Questions