admin管理员组文章数量:1336396
I have this code snippet:
<div id="div1">
</div>
<div id="div2">
<h3>This is the content</h3>
<script type="text/javascript">
alert('This is the content');
</script>
</div>
<script type="text/javascript">
jQuery('div#div2').appendTo('div#div1');
</script>
Using this code, alert message will be displayed twice (once when the page is loading, and then when jQuery re-execute the script when it execute appendTo method?
Any idea of how to use jQuery to conveniently move element (that have script tag) around without re-executin the javascript?
Thanks.
I have this code snippet:
<div id="div1">
</div>
<div id="div2">
<h3>This is the content</h3>
<script type="text/javascript">
alert('This is the content');
</script>
</div>
<script type="text/javascript">
jQuery('div#div2').appendTo('div#div1');
</script>
Using this code, alert message will be displayed twice (once when the page is loading, and then when jQuery re-execute the script when it execute appendTo method?
Any idea of how to use jQuery to conveniently move element (that have script tag) around without re-executin the javascript?
Thanks.
Share Improve this question asked Jun 25, 2009 at 3:27 NordinNordin 3,2876 gold badges30 silver badges35 bronze badges1 Answer
Reset to default 11Once the <script>
has executed you don't need it any more, so you could remove it before moving #div2
.
$('#div2 script').remove();
$('#div2').appendTo('#div1');
版权声明:本文标题:javascript - How to Move Element With Script Element Without Re-Executing Script with jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742374108a2462815.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论