Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to dyamically change content on page?

    How can I , for example, replace an image with another image, or some text, Or change the information in some text. But All this has to happen dynamically and without refreshing the page. How can this be achieved best?

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Posts
    206
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I would use the Document Object Model. Example:

    JavaScript:
    Code:
    function changeText()
    {
    var newText = document.createTextNode('This is the new text.');
    var container = document.getElementById('textDiv');
    container.replaceChild(newText, container.firstChild);
    }
    XHTML:
    Code:
    <div id="textDiv" onclick="changeText()">
    This is the old text.
    </div>
    Note that the change need not be user-prompted. You can call changeText() upon window.onload or whe(r|n)ever you want...

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    70
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks man: exactly what I was looking for, but how could I make a timer instead of the onclick function?


  •  

    Posting Permissions

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