pktm
pktm

Reputation: 23

XMLSerializer skips element values

I've got some Javascript code which serializes the entire DOM tree as follows:

(new XMLSerializer()).serializeToString(document)

But what I get is somewhat different than I'd expect. Specifically, I get the HTML source, but not the values of the various input/selects. If objects are inserted into the DOM, I get those objects, but again, no values.

However, if I were to walk through the DOM in Javascript for some other purpose, I would have access to every input's value.

What gives? Obviously, I'm missing some very basic concept, but I've no idea what.

Can I get the full DOM as an HTML/XML formatted string, with input/select values? If so, how?

Upvotes: 2

Views: 534

Answers (1)

Tim Down
Tim Down

Reputation: 324477

This is due to the fact that a DOM form input maintains its value property (which reflects the current state) separately from its value attribute (which represents the initial value of the input and is used by XMLSerializer to serialize the DOM).

I've written about this several times on Stack Overflow. Here's a recent example: jQuery .attr('value', 'new_value') not working?

Upvotes: 2

Related Questions