How to use document.write to update a div
The method object.appendChild (..) does not update the document ( no view source) therefore in some complex cases, it does work for me.
Are there anyway to use document.write to update a div?
if you want to update the div let say for example the div id is myDiv and you want to put html element on it example a button. you can simple use
document.getElementById("myDiv").innerHTML = "<input type='button' value='Ok'>";
Can you give us some more specifics on what your trying to accomplish? You mention Ajax so there must be some server side data you want to insert into a div or perhaps refresh on a timed interval?
document.write() is used only during the load of HTML documents. It does not work with XHTML.
document.write() does not work on already loaded documents.
Once you have a loaded document, you can use DOM methods to add or remove nodes to existing nodes. Nodes in an HTML DOM correspond to elements in the HTML markup. To work from a particular node, you should use an 'id' attribute in the markup and then use the DOM method (document.getElementById('id-attribute-value') to assign it to a JS variable, from which you can use methods or reference properties for a node of element type. Another type of node in the HTML DOM is a text node, and it has its own methods and properties. I suggest you get the PDF on the W3C HTML DOM Core and for HTML elements so you can understand what the methods and properties are.
Moreover, if you want to track the result of changes you make to by your use of the methods, I suggest you install & use Firefox and then install the add-on Firebug: this allows you to interact with the document and identify the HTML markup, CSS styling, aspects of DOM. "View Source" is rendered at load time, and probably does not incorporate dynamic changes to the document done by scripts.
Originally Posted by DanInMA
The current project require to update a tree view with many branches.
When a user click any nodes, I need to update that node only, not a whole tree
Here is my example:
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread