Is there a way to retrieve a specific CSS property of an element, even if it is inherited from its parent?
The standard jQuery method .css() can help with this.
Consider the following HTML structure:
<div id="container"> some text<br>
<span id="some">Our element</span>
<br> some text
</div>
<div id="result">
</div>
Defined CSS styles:
#some {
font-weight:bold;
}
#container {
text-decoration: underline;
color: rgb(0,255,0);
font-size: 32px;
}
and jQuery script:
$(function() {
var decor = $("#some").css('text-decoration');
var weight = $("#some").css('font-weight');
var color = $("#some").css('color');
var size = $("#some").css('font-size');
var result = "<br><b>our object's own property:</b>"
result += "<br>font-weight:" + weight + "<br>";
result += "<br><b>inherited properties:</b><br>";
result += "color: " + color + "<br>font-size: " + size + "<br>text-decoration: " + decor;
$("#result").html(result);
});
All CSS properties are displayed except for text-decoration. Want to know why? http://jsfiddle.net/aQYs2/