...

View Full Version : change div content via java scirpt



hno2005
07-02-2011, 08:21 AM
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

abduraooft
07-02-2011, 08:45 AM
<script>
window.onload=function(){
document.getElementById("test").innerHTML= "ddd";
}
</script>
<div id="test">dude</div>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum