I know how to replace text with getElementById() function in such situation:
<script type="text/javascript">
function go(){
var p = document.getElementById('ccc');
p.firstChild.nodeValue = 'AAA';
}
</script>
<div id='ccc'>o</div>
<a href="javascript:go()">go</a>
When I click on go link 'o' replaces on 'AAA'.
But I want to replace text when page loading to browser without any clicking. So user do not have to know that there was some text 'o' in div 'ccc'. He must see only 'AAA' from the beginning.
How to do that?
You can use the onload event:
window.onload = go;
// or better
window.addEventListener("load", go);
You can also use an anonymous function:
window.onload = function()
{
// ...
}
window.addEventListener("load", function()
{
// ...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With