How to get css properties set explicitly via the style attribute? [closed]


Tags: javascript,css

Problem :

How do I find all the css properties set explicitly via the style attribute?



Solution :

Let's say you wanted to get the styles of an element named "myp":

var stylez = document.getElementById("myp").style;
var ix;
for (ix = 0;  ix < stylez.length;  ++ix) {
    console.log(stylez.item(ix) + ": " + stylez.getPropertyValue(stylez.item(ix)));
}

Working JSFiddle here produces output:

font-weight: bold

Only the info in style is output, even though a class sets a font size and a CSS directly applies a background color.

You could also read the style attribute text and parse it yourself, which is less accurate but if you wanted to include invalid statements you'd need this.


    CSS Howto..

    How to create two column in form using css

    How to display inline with rails?

    How to align multiple images horizontally (in a row)?

    How to make possible vertical scroll on popup and disable vertical scroll for page by using CSS?

    how to collapse width of parent element to total width of child elements

    How to add and remove a current state to a link when another is clicked using jQuery

    How to embed fonts in CSS?

    How to create new lines with less space HTML/CSS

    How to create a texture paper background using CSS without image

    How do you find the dimensions of a “display: none” element?

    How to make TD behaving like TR(row) with CSS?

    How to filter elements on click in js?

    How would you style this html so that everything falls into a table?

    How can I align multiple lists in the same row?

    How to center align social media tags using HTML and CSS

    How to solve Firefox 2.0 cross browser issues?

    How to create a custom vaadin component in vaadin 6

    How to modify css in OpenERP 7?

    Is there a plugin for Wordpress that lets me show HTML/JS/CSS examples? [closed]

    Class inside of Div not showing properly

    How to display a button over a picture only when hovering it?

    how to make background-image included via a “class” responsive

    How to add physics to CSS animations?

    How to cycle odd and even when using ajax append?

    How can i make an icon blink using CSS/javascript/jquery [duplicate]

    how i can select some attribute value from in line css

    How to select a range of elements in repeated pattern

    how to get 2 div's text to align along the bottom?

    how to add border to CSS only speech bubble

    Node/Grunt - Autoprefixer - How to add configuration to my Gruntfile.js & how to check supported browsers?