Is it possible to determine if an item’s style is only the browser default value, set styles or inline styles?

My javascript is included in the X site, but I have no other control over its site or where it is included. If she’s in style #element, I want to leave her alone, but if she doesn’t, I will have a style sheet that I will introduce into <head>. Is there any way to determine if she wrote her style?

The height check is 0 or 1 because it has some content and the browser makes decisions by default.

In any case, for javascript / jquery / other framework to talk about the specifics of CSS style, the answer to this will be incredible.

+5
source share
2 answers

, , , , style class .

http://jsfiddle.net/YbSpc/

HTML

<div id="test_unstyled"></div>
<div id="test_styled" style="background-color: red;" class="something"></div>

JS

var unstyled = document.getElementById('test_unstyled'),
    styled = document.getElementById('test_styled');

console.log('test_unstyled is styled?', !!(unstyled.getAttribute('style') || unstyled.className));
console.log('test_styled is styled?', !!(styled.getAttribute('style') || styled.className));

- , CSS. , , , , , , , , .

, , API, , .

, , .

0

: element.style , - element.hasAttribute('style'), , HTML.

CSS, , " , CSS Javascript?", , .

, , #element, (, ).

0

All Articles