Skip to main content

Bug Tracker

Side navigation

#9134 closed bug (duplicate)

Opened May 05, 2011 11:26PM UTC

Closed October 31, 2012 01:08AM UTC

wrapInner causes scripts in body to be run twice

Reported by: Nicholai Burton <nicholai.burton@gmail.com> Owned by: gibson042
Priority: high Milestone: 1.next
Component: manipulation Version: 1.6
Keywords: Cc:
Blocked by: Blocking:
Description

If wrapInner is called from within the body of a page, it runs itself twice, and any other scripts in the body run twice regardless of where wrapInner is run. Consider this code snippet to duplicate.

<head>
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
</head>
<body>
	<div id="initialdiv">this is the main div at first</div>
	<div id="anotherdiv">this is another div at first</div>

	<script type="text/javascript">
		$(document).ready(function() {
			$('body').wrapInner('<div id="bodywrap"></div>');
		});

	alert("watch me duplicate");
	</script>

</body>
Attachments (0)
Change History (10)

Changed May 06, 2011 04:08AM UTC by jboesch comment:1

In my opinion, this feels like a weird way to be using wrapInner... this seems like it's expected that it would re-run the script block if it has to restructure the DOM.

In any case, here is the jsfiddle: http://jsfiddle.net/jboesch26/5ynpG/

Changed May 06, 2011 12:30PM UTC by Nicholai Burton <nicholai.burton@gmail.com> comment:2

The use case is for when you don't have control of a page's source code and need to modify it (in my case to wrap it in two divs with margin:auto on each, to center the page). The docs describe the method as a way to move elements around, but it appears to be recreating them. With traditional JS I would do this: http://jsfiddle.net/adGZS/. So it may just be a documentation issue if there is an alternative jQuery method to wrap items by just moving the children into the wrapper.

Changed May 06, 2011 03:50PM UTC by timmywil comment:3

component: unfiledmanipulation
priority: undecidedhigh
resolution: → duplicate
status: newclosed

Changed May 06, 2011 03:50PM UTC by timmywil comment:4

Duplicate of #3105.

Changed July 11, 2011 05:49PM UTC by dmethvin comment:5

resolution: duplicate
status: closedreopened

We're going to reopen this and try to fix it internally. Anyone who manually removes and then reinserts scripts is responsible for making sure they don't re-execute.

Changed July 11, 2011 05:49PM UTC by timmywil comment:6

status: reopenedopen

Changed January 26, 2012 02:14PM UTC by dmethvin comment:7

#11227 is a duplicate of this ticket.

Changed October 16, 2012 05:09AM UTC by mikesherov comment:8

blockedby: → 11795

Changed October 16, 2012 05:10AM UTC by mikesherov comment:9

owner: → gibson042
status: openassigned

Changed October 31, 2012 01:08AM UTC by gibson042 comment:10

resolution: → duplicate
status: assignedclosed

Duplicate of #10470.