Reputation: 4609
When an AJAX request is made, and a subsequent change is made to the DOM tree (for example, replacing the contents in a DIV with the responseText), why is it that when I view source on the updated page, the HTML does not reflect the changes? The page has definitely changed, but the source looks the same.
Upvotes: 1
Views: 485
Reputation: 972
Page Source is the original source for the page when it's loaded. Because the changes that are made with javascript are all client side, you are not actually changing the source, but instead the client side rendering.
If you want to see the client side version of the DOM, you can inspect element in a browser to the view the DOM dynamically as it changes when a script interacts with it.
When you are using javascript to manipulate the DOM, you are actually manipulating the document
object. For example:
document.getElementById("myid").id = "newid";
Here changes are being made to the document object, not to the source of the page. Still, those changes are reflected in the rendered document object and shown to the user.
To further emphasize this, here is the DOM as defined by Microsoft Developer:
The Document Object Model (DOM) as implemented in MSXML provides a programmatic representation of XML documents, fragments, nodes, or node-sets. It also provides an application programming interface for working with XML data. As an XML representation, it conforms to the W3C DOM specification.
Upvotes: 4