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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question document.write(string) so why not div.write(string) ?

    Hi !

    I've created a labelled <div> section, and want to know if there is a javascript command to write something in the <div> section (like the document.write(string) command does to the wole document)

    thx ;-)

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    give the div an id
    <div id="divid"></div>
    <script type="text/javascript">
    document.getElementById("divid").innerHTML = "hi";
    </script>
    you could also put html in the div just like you could w/ document.write();

  • #3
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks ! I found the code

    Thanks !

    Your code is great but try this one :
    It works both on IE and Mozilla

    <script>
    function WriteDiv(text, id) {

    if (document.getElementById) {
    x = document.getElementById(id);
    x.innerHTML = '';
    x.innerHTML = text;
    }
    else if (document.all) {
    x = document.all[id];
    x.innerHTML = text;
    }
    }
    </script>

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Simplified, assuming that it's IE or Mozilla:

    <script>
    function WriteDiv(text, id)
    {
    x = document.all?document.all[id]:document.getElementById(id);
    x.innerHTML = text;
    }
    </script>
    Don't resist to assimilation. Billions of Borgs can't be wrong!


  •  

    Posting Permissions

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