I am trying to see if an element have a specific CSS attribute. I am thinking at something like this:
if ( !$(this).attr('font-style', 'italic')) {
alert ("yop")
}
else {
alert ("nope")
}
It does not work. Any tips on this? Thank you!
Here's a simple plugin to do that (tested):
$.fn.hasCss = function(prop, val) {
return $(this).css(prop.toLowerCase()) == val.toLowerCase();
}
$(document).ready(function() {
alert($("a").hasCss("Font-Style", "Italic"));
});
<a style="fonT-sTyle:ItAlIc">Test</a>
You are trying to get a css style. The css method can get the information
if ( !$(this).css('font-style') == "italic") {
alert ("yop")
}
else {
alert ("nope")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With