Search code examples
jquery

How to select a checkbox using an attribute value? (jquery)


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?


Solution

  • 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);