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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts

    change div content via java scirpt

    HI every one
    I want to change a div content in my page via javascript , the problem is the index.php file is coded and I can't read it , but I could execute some JavaScript codes from somewhere else .

    The problem is that the <div> is in the lowest side of the page and my javascript code is above it , so The javascript code runs first and It couldn't find the div because it's not loaded yet .

    my javascript code is something like this :

    <script>
    document.getElementById("test").innerHTML= "ddd";
    </script>
    <div id="test">dude</div>


    in the example above , it's not working But if I insert the JavaScript below the <div> it's working .

    How can I run it in this example ? If the javascript code is above the <div> , how can I change the div's content ?

    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    <script>
    window.onload=function(){
        document.getElementById("test").innerHTML= "ddd";
    }
    </script>
    <div id="test">dude</div>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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