I want to check right padding value of div element. I use jquery .css() method:
$('div').css('padding-right');
It works. Now I need to know where it value comes from. It can by inline defenition:
<div style="padding-right: 100px;">
or it can be wrote in external css file (or <style></style>
section):
div {
padding-right: 100px;
}
Thanks!
jQuery css() Method The css() method sets or returns one or more style properties for the selected elements. When used to return properties: This method returns the specified CSS property value of the FIRST matched element.
replace(/display[^;]+;?/g, ''); }); This will remove that inline style.
The css() method in JQuery is used to change the style property of the selected element. The css() in JQuery can be used in different ways. Return value: It will return the value of the property for the selected element.
Get a CSS Property Value You can get the computed value of an element's CSS property by simply passing the property name as a parameter to the css() method. Here's the basic syntax: $(selector). css("propertyName");
According to the css() documentation
Get the computed style properties
and
Note that the computed style of an element may not be the same as the value specified for that element in a style sheet. For example, computed styles of dimensions are almost always pixels, but they can be specified as em, ex, px or % in a style sheet. Different browsers may return CSS color values that are logically but not textually equal, e.g., #FFF, #ffffff, and rgb(255,255,255).
Therefore, at the end, whether its from an inline style or a style sheet, it is the computed style.
Try using developer tools in your browser of choice. Right click the div -> "inspect element" (or similar) and look at the CSS for that element. Find your 'padding-right', and it should show you the source for that rule.
You can check if your element has inline styles testing "style" property of the DOM element
$("div")[0].style
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