5

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!

Cypher
  • 352
  • 2
  • 13
  • Inline style has priority over CSS class – Satpal May 28 '15 at 10:59
  • You can inspect the element in developer tools in Chrome and add a break point on Attributes modification, and refresh the page. If the page 'freezes' on refresh then you'll see where the change came from if it was from javascript injection. If nothing happens, then it means that it was an inline style and it was there from the beginning... – dingo_d May 28 '15 at 11:09
  • See: http://stackoverflow.com/questions/2952667/find-all-css-rules-that-apply-to-an-element – A. Wolff May 28 '15 at 11:12
  • I know about priority. About dev tools too. Thanks. I need to know it from js/jquery. – Cypher May 28 '15 at 11:49

3 Answers3

4

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.

Community
  • 1
  • 1
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53
1

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.

Alex McMillan
  • 17,096
  • 12
  • 55
  • 88
1

You can check if your element has inline styles testing "style" property of the DOM element

$("div")[0].style
gmast
  • 192
  • 8