Jquery Do not allow Click on a Button that has a certain CSS Class

Asked

Viewed 176 times

1

Good morning Guys, I have an application with Jquery Easyui, and I always call the button click actions with Jquery, as an example below:

$("#btnEditar").click(function(){
  ...
});

It happens that when you click the button and it is disabled, it continues to perform the Jquery Click action.

I wonder if it would be possible to run the Button Click only if it is without a certain css class, in my case . l-btn-disabled. I performed the test as below but it did not work:

$("#btnEditar").not(".l-btn-disabled").click(function(){
  ...
});

Grateful for the attention.

  • that element #btnEditar is a button or a input[type=button]?

1 answer

2

You can use it like this, using :not():

$("#btnEditar:not('.l-btn-disabled')").click(function(){

But note that you are using an ID in your selector, and ID must be unique. Use classes in the Buttons that you want to select ID instead.

Example: https://jsfiddle.net/my78aLr1/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.