How to use NOT selector for selector of .on() using jquery?

158 Views Asked by At

I'm currently using this to select fields:

$('body').on('change', '#mainFrom input', function(){

How do I apply a not selector for class listName ?

I've tried :

$('body').not('.listName').on('change', '#mainForm input', function(){

Which didn't work.

How do I do this ?

Thanks

2

There are 2 best solutions below

1
T.J. Crowder On BEST ANSWER

I'm going to guess that the listName class will be on the input. If so:

$('body').on('change', '#mainForm input:not(.listName)', function(){
// ------------------------------------^^^^^^^^^^^^^^^

Or if we guess that it's on #mainForm:

$('body').on('change', '#mainForm:not(.listName) input', function(){
// ------------------------------^^^^^^^^^^^^^^^

Or if we guess that it's on body, we have to change more:

$( document ).on('change', 'body:not(.listName) #mainForm input', function(){
// ^^^^^^^^-----------------^^^^^^^^^^^^^^^^^^^
0
Bhojendra Rauniyar On

Use like this:

$('body').on('change', '#mainForm input:not(.listName)', function(){