dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: How to use document.write to update a div

  1. #1
    Join Date
    Apr 2011
    Posts
    4

    How to use document.write to update a div

    Hi everyone,


    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

  2. #2
    Join Date
    Apr 2011
    Location
    I live in the pinaple under the sea
    Posts
    107
    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

    HTML Code:
    document.getElementById("myDiv").innerHTML = "<input type='button' value='Ok'>";

  3. #3
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    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?

  4. #4
    Join Date
    Jun 2009
    Location
    Miami
    Posts
    118
    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.

  5. #5
    Join Date
    Apr 2011
    Posts
    4
    Quote Originally Posted by DanInMA View Post
    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:

    Root
    .. Child1
    .. Child1.1
    ..Child1.2

    .. Child2

    .. Child3
    ... Child3.1
    ... Child3.1.1

    thanks,
    Jdang

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles