tags:

views:

445

answers:

5

Hi all.

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

+5  A: 

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.

Andy Gaskell
+1  A: 

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);
Ferdinand Beyer
+1  A: 

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

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

try this:

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

This should do it:

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