简体   繁体   中英

jQuery - move element with javascript inside

I'm using jquery to move a element that contains javascript code inside it, like this:

<li class="a1">
 <div class="el"> 
    <script type="text/javascript"> document.write('Hello World'); </script>
    ...
 </div>
</li>

<li class="a2">     
</li>

<a class="trigger">link</a>

so I attached a click event on a.trigger that will move div.el into the 2nd list. the problem is that the js inside it makes the browser to open a new window only with div.el inside it :(

Don't use document.write because it will cause headaches. Enhance progressively:

$(".el").html('Hello World');

And it will work just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM