Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this inline style or css file style returns with jquery .css()

Tags:

jquery

css

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!

like image 789
Cypher Avatar asked May 28 '15 10:05

Cypher


People also ask

What is the use of CSS () method in jQuery?

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.

How to remove inline style in jQuery?

replace(/display[^;]+;?/g, ''); }); This will remove that inline style.

How to set style property in jQuery?

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.

How can check CSS property value in jQuery?

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");


Video Answer


3 Answers

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.

like image 63
AmmarCSE Avatar answered Oct 17 '22 05:10

AmmarCSE


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.

like image 31
Alex McMillan Avatar answered Oct 17 '22 05:10

Alex McMillan


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

$("div")[0].style
like image 1
gmast Avatar answered Oct 17 '22 06:10

gmast