Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a click event with ".on" based on element class excluding certain elements

Tags:

jquery

I need to bind a click event to the elements with class '.rows', but I want to exclude one of them bearing the id '#unsigned'.

I am using ON command like this:

$('.container').on('click', '.rows', (a_function_to_run));

I was expecting this:

$('.container').on('click', '.rows',':not(#unsigned)', (a_function_to_run));

or this

$('.container').on('click', '.rows', (a_function_to_run)).not('#unsigned');

to work.

What is the right syntax? Thank you in advance for your help.

like image 613
Panos Kal. Avatar asked May 22 '26 07:05

Panos Kal.


1 Answers

You can add :not() in the selector:

$('.container').on('click', '.rows:not(#unsigned)', function() { ... });
like image 74
VisioN Avatar answered May 23 '26 22:05

VisioN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!