rain13 Posted December 26, 2011 Share Posted December 26, 2011 does anyone know why doesnt this simple code work? <script type="text/javascript">function foo(){alert("Hello World!");}</script><p onload="foo();"><p> also tried <p onLoad="alert('hello')"></p> My goal to run js when given item is loaded. Link to comment Share on other sites More sharing options...
TheGallery Posted December 26, 2011 Share Posted December 26, 2011 Try removing the semicolon ( ; ) from the <p onload="foo()"></p> (and close your paragraph tag) Link to comment Share on other sites More sharing options...
JamesB Posted December 26, 2011 Share Posted December 26, 2011 hmm i don't think the <p> tag supports the onload event,if you want to run js code after the browser has read the <p> tag: <p></p><script type='application/javascript'>foo()</script> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.