Skip to content Skip to sidebar Skip to footer

Is It Possible To Get The Value Of A Dom Element's Specific Css Attribute From The External Stylesheet And Not The Computed One?

The jquery .css method does not work for this. Is there an alternate one to get the real value in the css sheet like a percentage ect... ? Here is an example which show that .css d

Solution 1:

I do not think there is a built-in function for this. I'm not sure what you mean by "going in the css as a string," but you could easily calculate the percentage.

var percent = (parseFloat(Marginleft)/parseFloat($(domElem).parent().css('width')) * 100) + '%';
alert(percent);

Solution 2:

Try this (Webkit only: Chrome, Opera, Safari)

varMarginleft = window.getMatchedCSSRules(domElem)[0].style["margin-left"]
alert(Marginleft);

This example would read "margin-left" style property from the first assigned class to the dom element. If you have multiple classes - you may have to loop thru the array to get the class you're intested in.

Demo: http://jsfiddle.net/rkT5Q/

For Gecko alternative take a look at https://gist.github.com/ydaniv/3033012

For a possible cross-browser one at https://stackoverflow.com/a/4926651/961695

Post a Comment for "Is It Possible To Get The Value Of A Dom Element's Specific Css Attribute From The External Stylesheet And Not The Computed One?"