Why is the following jQuery code freezing my browser?
Caution: do not run this if you are not ready to force exit the browser
<!DOCTYPE HTML> <title>Simple clone</title> <script type="text/javascript" src="jquery.js"></script> <div> <script>$('div').clone().appendTo('body');</script> </div>
Edit
For those who are in the “endless cycle” camp, this should not be a problem. Perfectly safe version (non-jQuery):
<div>div <script> var el = document.getElementsByTagName('div')[0]; document.body.appendChild(el.cloneNode(true)); </script> </div>
So the problem is how jQuery does cloning.
Edit 2
JQuery seems to call script elements in clones. This is not standard behavior and something about how jQuery makes clones, which is completely unexpected.
source share