0

At the moment I have a page where users can create divs and drag/drop them into another div id="holder".

I have a save button that gets the html of holder. $('#Holder').html();

The divs in holder have some styling from a CSS file and inline styling: style="left:10px; right:10px; background-color:#000000;" added by jQuery.

What I want is to combine the styling from my CSS file with the inline styling so I am able to use $('#holder').html(); and have all styles.

Question: How can I parse the CSS styling into the style="" attr.

So after the info an example of what I have: http://jsfiddle.net/Ub9ZD/

As you can see im missing the width, height and position style.

== EDIT ==

After looking at given link I'm still stuggling with this.

I still can't combine the inline style and CSS style from file.

Progress: http://jsfiddle.net/Ub9ZD/39/

Ron van der Heijden
  • 14,803
  • 7
  • 58
  • 82
  • Here's the answer for your same question asked ~3 years ago: [little link](http://stackoverflow.com/a/5830517/364869). – Chris Sep 07 '12 at 11:49
  • this will help. http://stackoverflow.com/questions/754607/can-jquery-get-all-css-styles-associated-with-an-element – loler Sep 07 '12 at 11:53
  • @Abody97 @loler Still not quite my answer. Above function take only from the given `#holder` but I need also the children of this `#holder` – Ron van der Heijden Sep 07 '12 at 12:41

1 Answers1

0

That's not as easy as it sounds, not by a long shot. If you want to look at an object's CSS properties, you can use the .css() function jQuery provides. Essentially, you'd retrieve each of the element's styles via the .css() function and reapply them to the element with the htmlELement.style method. Then, theoretically, .html() would give you a list of all the CSS styles on that element.

Are you sure that's what you need, or can you just use .css() the way it's intended?

Elliot Bonneville
  • 51,872
  • 23
  • 96
  • 123