Priyank
Priyank

Reputation: 14387

Jquery Selectors And Condition

We have a requirement in application that on clicking on all images which do not have a css class of "xyz" we want to call a function. We are trying to write it somehwhat like this:

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

It doesn't seem to work. Ideal scenario would be that all images on clicking does some functionality except the one which has CSS as "xyz".

What am I doing wrong?

I am using input, as I use JSF and this command button is being displayed as an input type component with src as image.

Thanks for your help in advance. Cheers

Upvotes: 3

Views: 6909

Answers (5)

Andy Gaskell
Andy Gaskell

Reputation: 31761

I think you want to use not.

This should do it:

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

You may also be able to use the not selector.

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

The function version seems more expressive to me.

Upvotes: 7

Greg
Greg

Reputation: 321588

This should do it:

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

Upvotes: 1

mck89
mck89

Reputation: 294

try this:

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

Upvotes: 1

TheVillageIdiot
TheVillageIdiot

Reputation: 40497

you can remove elements from selection having certain class or id using not function:

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

Upvotes: 1

Ferdinand Beyer
Ferdinand Beyer

Reputation: 67137

We have a requirement in application that on clicking on all images which do not have a css class of "xyz" we want to call a function.

That should be pretty intuitive using JQuery:

  • Select all images
  • Filter out those which match your CSS class

Code:

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

Upvotes: 1

Related Questions