How to get string with literal string text using JavaScript?

I found the need to extract the element set style in the browser (made by the user). I should be able to work with extracted styles on my server (server side javascript and jQuery). Now the problem is that many browsers use their own naming conventions or like to split abbreviations into separate elements, while others do not.

One solution for me would be to get an element style literal string (styles from style sheets should not be taken into account). In Firefox / Chrome, this will work:

node.getAttribute('style')

Unfortunately, this is not possible in Internet Explorer 5/6/7. I decided that this would be the solution:

function getStyleStr(node) {
    return typeof(node.getAttribute('style')) !== 'string' ? node.style.cssText : node.getAttribute('style');
}

http://jsfiddle.net/8p5BN/6/

Unfortunately, node.style.cssText does not return a literal string, as described here: http://javascript.gakaa.com/style-csstext.aspx

Is there a better way to define the style of an element set in a cross browser with the same name?

+3
source share
1 answer

http://upshots.org/?p=112

You need to access the computed style and the current style of the dom element. This should give you everything you need, and it will take into account all forms of styles (inline, declared css and inherited properties).

+3
source

Source: https://habr.com/ru/post/1775980/


All Articles