JQuery selectors and state

We have a requirement in the application that when we click on all images that do not have the css "xyz" class, we want to call the function. We are trying to write it something like this:

$('input[type=image] class=xyz').click(function(){//something});

It does not seem to work. The ideal scenario would be that all the images when clicked perform some functionality, except that which has CSS as "xyz".

What am I doing wrong?

I use input as I use JSF and this command button is displayed as a component of input type with src as image.

Thanks for your help in advance. Greetings

+3
source share
5 answers

I think you want to use not .

This should do it:

$('input[type=image]').not(".xyz").click(function(){//something});

not selector.

$('input[type=image]:not(.xyz)').click(function(){//something});

.

+7

, , css "xyz", .

JQuery:

  • , CSS

:

$('input[type=image],img').not('.xyz').click(myFunc);
+1

you can remove elements from a selection that have a specific class or identifier using a non- function:

$("input[type=image]").not(".xyz").click(function(){....});
+1
source

try the following:

$('input[type=image][class!=xyz]').click(function(){//something});
+1
source

This should do it:

$('input[type=image]:not(.xyz)').click(function(){//something});
+1
source

Source: https://habr.com/ru/post/1715866/


All Articles