Search code examples
jqueryasp.net-mvccheckboxcheckboxfor

Prevent a read-only checkbox from calling a event handler?


I have a list of checkboxes with the same syntax below, some of them are read-only:

@Html.CheckBoxFor(model => model.SrsSettingList[i].LeftPickup, new{ @class= "chkSRSPickup"})

First I want to mention that I cant use "disabled" atrribute in this case. Please dont tell me to do that. Below is my event handler when I click on the checkbox:

 $(document).on('click', '.chkSRSPickup', function () {

blah blah...

    });

I dont want to call the function when I click on read-only checkboxes. How can I do that?


Solution

  • Use :not() like

    $(document).on('click', '.chkSRSPickup:not([readonly])', function () {