Reputation: 7185
I want to create the event based on data attribute instead of class name
<button type="button"
class="btn btn-danger approvalbtn" data-approvestatus="N" data-dismiss="modal">Reject</button>
Now I have added attribute as `$('.approvalbtn').prop("disabled",true);`
I want to check with data-approvestatus="N"
in jquery
Upvotes: 1
Views: 70
Reputation: 10148
$('button[data-approvestatus=N]').click(function(){
alert("Clicked");
//$(this).prop("disabled",true) you can disable it too
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button"
class="btn btn-danger approvalbtn" data-approvestatus="N" data-dismiss="modal">Reject</button>
Upvotes: 5
Reputation:
You're looking for the attribute selector! This is how:
$("[data-approvestatus='N']").prop("disabled", true);
Docs: https://api.jquery.com/attribute-equals-selector/
Upvotes: 1