xdevel2000 xdevel2000 - 4 months ago 37
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??


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