0

I have divs. They can be drag, resizable and i have a div editor.That means i can change any div width,height,margin,padding and it background-color,font-size,font-weight etc.I done this using jquery and i did it perfectly.Now what i want to know How i get all css properties with the each div.

When i done using jquery each div element,style properties changing...

element.style{
width:250px;
height:35px;
top:233.23px;
left:33.12px;
background-color:#000;
font-size:16px;
font-weight:600;


}

like that.So i want to get all above values to the jquery object to create json file.How can i achieve this ?

3

2 Answers 2

2

Based on this answer: Can jQuery get all CSS styles associated with an element?

Here's a demo: http://jsfiddle.net/tymeJV/TFaZ3/

The result console.log(css($(".test"))); == Object {600: "", width: "250px", height: "35px", top: "233.23px", left: "33.12px", background-color: "rgb(0, 0, 0)"…}

Seems to accomplish what is needed.

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

1 Comment

cool.. but then you forgot to add the function css(){... here.. without that i doubt this will work.. i assume, you 'll get an error saying css is not defined ... :)
0

You use must first set a class with CSS and then use 'addClass' instead of 'css' with jQuery. See the example I have below:

.class {margin:0; padding:0; text-align:center; }

And then you jQuery would look something like this:

(function() { $('selector').addClass('class'); })(jQuery);

Comments

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.