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 ?

Dilini Wasana
  • 267
  • 1
  • 3
  • 11

2 Answers2

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.

Community
  • 1
  • 1
tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • 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` ... :) – bipen May 15 '13 at 17:59
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);
Mosire
  • 129
  • 3
  • 12