0

How to get all css property and its value from an element ?

I am trying to make a plugin for live editing css of an element. If an element have already any style then get it and append value to input fields so that I can edit already set styles.

I dont have the property name, so how to run a loop and and get all css property and its value. and then put it an array.

my dummy code

function get_css(elem){
    var newObj = {};    
    elem.each(function(){
        var css = this.css('?');
        newObj[parts[property]] = parts[value];
    });
    return newObj;           
}

Here is the fiddle http://jsfiddle.net/howtoplease/4Nv2C/

6
  • 1
    Take a look at [stackoverflow.com/questions/754607/… [1]: stackoverflow.com/questions/754607/… Commented Jul 20, 2013 at 10:12
  • Do you want want all CSS rules computed for an element (except maybe inherited ones???) or all the CSS rules you have declared for an element? This is not the same thing. Commented Jul 20, 2013 at 10:20
  • by <<Only applied css>> you mean only style you have declared in CSS, right? If ya, this could be more accurate: stackoverflow.com/questions/9180184/… Commented Jul 20, 2013 at 10:27
  • If you could explain why you would need all the css in an array, maybe someone can help you out with an alternative solution, as you're almost certainly going about this the wrong way as this is not something you would normally have to do. Commented Jul 20, 2013 at 10:29
  • 1
    See this answer stackoverflow.com/a/16935800/2522817 I tested it in Chrome and works. Take a look at typo in 6th line mentioned in comment. Commented Jul 20, 2013 at 11:55

1 Answer 1

0

maybe you could put properties in object

myObj : {

color: 'black'; }

and then maybe you can go over with for in loop and take value or properties and then push into an array

for(var property in myObj){

console.log(property);

}
Sign up to request clarification or add additional context in comments.

1 Comment

my problem is that I dont have property name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.