I am working on a little project required Ajax. Therefor, I have to update the web page with javascript or Jquery. However, I run into some problem.
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?

thanks,

Jdang

04-28-2011, 02:27 PM

coldfire421

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

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?

04-28-2011, 03:10 PM

mavigozler

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.

04-28-2011, 03:40 PM

jdang

Quote:

Originally Posted by DanInMA

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?

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: