views:

160

answers:

1

i am trying to clone a particular div and do some manipulation to clear the content and return.

var tmp = $('<div>').append($('#masterdiv').clone()).remove().html();

It works fine in firefox. but in IE and chrome, this removed the entire div instead of cloning.

Whats the workaround for this?

Edit:

The main aim is to copy the entire master div and clear the contents inside the child divs and update it in the database using json. The actual master and child divs(which i take it as place holders for my content) will be rendered from database.

It should not clear the existing content unless the admin approves the layout.

So i tried to clone the div and manipulate, then the problem cames with the IE and chrome..

A: 

The first thing that catches my eye is that you are not passing a valid markup string to your $() function. For example, $('<div>') should become $('<div />')

From the jquery docs:

All HTML must be well-formed, otherwise it may not work correctly across all browsers. This includes the case where $("<span>") may not work but $("<span/>") will (note the XML-style closing slash).

There may be something else going on here for you, but this is the first thing you should correct.

Good luck!

Funka
i did as you said(well formed tags), but still the problem exists only in IE and chrome, it works well in firefox.
Prasad
The real problem is with the self closed html tag in the page. This has been solved when i corrected it.
Prasad