Panos Kalatzantonakis
Panos Kalatzantonakis

Reputation: 12683

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

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.

Upvotes: 3

Views: 90

Answers (1)

VisioN
VisioN

Reputation: 145428

You can add :not() in the selector:

$('.container').on('click', '.rows:not(#unsigned)', function() { ... });

Upvotes: 4

Related Questions