Jump to content

Dynamically add setInterval function


penguine

Recommended Posts

Hi How can setInterval function be added to head element. i want setInterval('checkstat()', 2000) to be created dynamically.i tried

					 var  head=document.getElementById('head');				 				var newscript = document.createElement('script');				newscript .type = 'text/javascript';							newscript .setInterval=function(){'checkstat()', 2000};				head.appendChild(newscript );

but it seems to be not working.

Link to comment
Share on other sites

I think you're trying to do this:

var  head=document.getElementByTagName('head')[0];				var newscript = document.createElement('script');newscript.type = 'text/javascript';			newscript.appendChild(document.createTextNode("setInterval('checkstat()', 2000)");head.appendChild(newscript );

But why create it dynamically? I still how doubts on if this will work, since once the browser finishes loading the head it most likely won't look back there again.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...