views:

49

answers:

3

I need to know when I click on an element if this element have a css option. I am thinking at something like this but it does not work:

if ($('#element').attr("text-shadow")) {
    alert ('i Have')
}
else {
    alert ('i dont')
}

Any tips on this one? Thanx

+3  A: 
if( $('#element').css('text-shadow') != null )  { 
    /*success*/ 
} 
else { 
    /*does not have*/ 
}
Stefan Kendall
Better to use `!== null`, am I wrong?
Matt Ball
for some reason this does not work. There must be something wrong with my code.
Mircea
It works for me with 1.4.2. Which version of jQuery are you using. Which browser? Can you provide a sample .html page and host it somewhere so I can debug the issue and see what's going on?
Stefan Kendall
@Bears: Maybe, but in this specific instance, the two should be equivalent, and your solution is an extra non-compressable byte :P.
Stefan Kendall
Sorry it was a browser thing. i restart it and works now.Thanx.
Mircea
A: 

$('#element').css("text-shadow")

prendio2
A: 

How about this instead:

if($('#element').css('text-shadow') == null) ...
Jimmy Baker
that answer's been posted 3 times already
prendio2
Yes, thank you. I opened this question before any answers had been posted then stepped away from my desk for a moment. My apologies.
Jimmy Baker