user3386779
user3386779

Reputation: 7185

event for data attribute instead of class name

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

Answers (2)

Muhammad Usman
Muhammad Usman

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

user4513271
user4513271

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

Related Questions