user1404602
user1404602

Reputation: 55

Jquery :NOT Selector Usage

$('body:not(selector)').fadeTo(100,0.3);

how can we do this selection's opencity like 0.3; i am using this not working right now

$('body:not(".myCLASS")').fadeTo(400,0.1);

Upvotes: 0

Views: 73

Answers (3)

Adriano Carneiro
Adriano Carneiro

Reputation: 58595

This is the working code:

$('body :not(.myCLASS)').fadeTo(400,0.1);

Update

Just updated the call, check the fiddle here: http://jsfiddle.net/mHVA5/

Upvotes: 0

Frédéric Hamidi
Frédéric Hamidi

Reputation: 262919

To apply the :not() selector to all elements, do not specify body:

$(":not(.myCLASS)").fadeTo(100, 0.3);

However, it would be more efficient to only match the top-level elements you want to fade instead of all of them (fading an ancestor element will affect its descendants). Maybe something like:

$("div:not(.myCLASS)").fadeTo(100, 0.3);

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68400

Not sure what you mean with "how can we do this selection's opencity like 0.3" but I'll add my 5 cents fixing the selector

$('body :not(.myCLASS)')

Body element doesn't make a lot of sense here. You could use better container like a div or just remove body from there.

$(':not(.myCLASS)')

If you happen to have a container to restric the search, you could do

$('#myContainerId :not(.myCLASS)')

Upvotes: 1

Related Questions