Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery check if element has css attribute

I need to know when I click on an element if this element has a CSS attribute. I am thinking of 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

like image 834
Mircea Avatar asked Apr 21 '10 18:04

Mircea


2 Answers

if( $('#element').css('text-shadow') != null )  { 
    /*success*/ 
} 
else { 
    /*does not have*/ 
}
like image 135
Stefan Kendall Avatar answered Nov 04 '22 12:11

Stefan Kendall


In case you want to test 'width' style property. Behavior in Firefox is slightly differ from other browsers.

if (jQuery(value).css('width') == '0px') { // width not set
    jQuery(value).css('width', '320px');
}
like image 22
yuliskov Avatar answered Nov 04 '22 14:11

yuliskov