xdevel2000 xdevel2000 - 1 year ago 112
JSON Question

JSON serialize a DOM element

If I do:

var el =
o : document.createElement("iframe")

var fs = JSON.stringify(el);

and then I try to access with

var ofs = JSON.parse(fs);

contains an empty object not the iframe elements WHY??

Answer Source

JSON (JavaScript Object Notation) is not designed for serializing DOM Nodes, you'll need to pull out the stuff you want by yourself and write it to an object, and then re-create the DOM Nodes from that if you need.

In fact, Chrome doesn't even execute your code:

TypeError: Converting circular structure to JSON
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download