Is there a way to give tags that do not support the onload attribute (such as div) a working onload attribute? Or would I have to mimic it by placing a script tag right after the desired tag?
Is there a way to give tags that do not support the onload attribute (such as div) a working onload attribute? Or would I have to mimic it by placing a script tag right after the desired tag?
You would probably have to do something like this:
Not sure if this is the best way, but hope this helps.Code:<div id="test">Some text</div> <script type="text/javascript"> window.onload = document.getElementById('test').innerHTML = 'This is a test'; </script>
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design
You can poll it:Is there a way to give tags that do not support the onload attribute (such as div) a working onload attribute? Or would I have to mimic it by placing a script tag right after the desired tag?Code:<script type="text/javascript"> function onExist(elID, func) { var v = document.getElementById(elID); if(!v) setTimeout(function() { onExist(elID, func); }, 500); else func.call(v); v = null; } onExist("test", function() { alert(this.firstChild.nodeName); }); </script>
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks