Possible Duplicate:
force Javascript to not execute till display =“inline”
I've got a div like the following...
<div id="tag" style="width: 360px; display:none">
<script type="text/javascript">
Crazy Wizardry Javascript here!
</script>
</div>
The Javascript inside is displaying.. is there a way that I can force it to not display on till I set the div to displa开发者_Go百科y "inline"?
It doesn't display at all: http://jsfiddle.net/XYUpJ/
But this is because that script tag does not output anything into that container. script
tags themselves are display:none
so you should never ever see their content.
If instead you mean you want the script to only run when the down that owns it becomes visible, then no you can't do that in this way. Visibile or not, a script tag just runs.
Instead you want to define a function in a script tag, and call that function when you set the #tag
to be visible.
精彩评论