Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get inline-style value even if element has the value also set in CSS?

If you have the following element:

<span style="width:100px"></span>

and the css is:

span {width:50px!important;}

Is there a way I can get the inline-style value and ignore the css value?

Thanks

like image 508
user2413333 Avatar asked Oct 02 '13 12:10

user2413333


People also ask

Why inline CSS is not recommendable?

The use of inline CSS styles prevent the reuse of the styles anywhere else. The html markup of the page becomes hard to read for the naked eye. The inline CSS styles are hard to maintain and does not provide consistency since they are not stored in a single place.

Are inline styles inherited?

As with any CSS declaration, inline styles are subject to inheritance. They can impact children if they declare an inheritable property. The inheritable color property affects any child element which doesn't explicitly declare the property itself. Aside from that, inline styles only have a local impact.

Does CSS overwrite inline style?

It works kind of counter-intuitively, so just to explain further: inline styles override internal CSS, and internal CSS overrides external CSS files, and external CSS files override browser defaults. One way to think about it is like layers. The “closer” the style is to the element, the higher precedence it has.

Which CSS style rules can you apply to an inline element?

Inline CSS allows you to apply a unique style to one HTML element at a time. You assign CSS to a specific HTML element by using the style attribute with any CSS properties defined within it. In the following example, you can see how to describe CSS style properties for an HTML <p> element in the same line of code.


1 Answers

use element.style.width

sample:

$(function(){
    alert($("span")[0].style.width);
});
like image 94
gp. Avatar answered Oct 04 '22 10:10

gp.