Skip to main content

Bug Tracker

Side navigation

#10177 closed bug (fixed)

Opened August 31, 2011 11:50AM UTC

Closed November 06, 2011 10:03PM UTC

Last modified November 06, 2011 10:04PM UTC

index of callback function in .wrap is always 0

Reported by: Owned by: rwaldron
Priority: high Milestone: 1.7.1
Component: manipulation Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:

I have the following HTML:

<div class="box">...</div>

<div class="box">...</div>

Using the following:

$J('').wrap(function(index) {
  return '<div class="boxwrap index_' + index +'" />'

I expect to get:

<div class="boxwrap index_0">
  <div class="box">...</div>
<div class="boxwrap index_1">
  <div class="box">...</div>

Error, I get always 0 for index:

<div class="boxwrap index_0">
  <div class="box">...</div>
<div class="boxwrap index_0">
  <div class="box">...</div>

The follwing workaround produces the expected result:

$J('').each(function(index) {
  $J(this).wrap(function() {
    return '<div class="boxwrap index_' + index +'" />';
Attachments (0)
Change History (5)

Changed August 31, 2011 02:13PM UTC by timmywil comment:1

component: unfiledmanipulation
owner: →
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: Open the link and click to "Fork" (in the top menu) to get started.

Changed September 01, 2011 07:29AM UTC by comment:2

status: pendingnew

Here is the link to the test using jQuery edge in jsFiddle: showing the bug.

Here is the link to the work around with the expected result:

Changed September 01, 2011 02:39PM UTC by rwaldron comment:3

owner: manuel@bouza.chrwaldron
priority: lowhigh
status: newassigned

Changed November 06, 2011 10:03PM UTC by Toby Brain comment:4

resolution: → fixed
status: assignedclosed

Fix #10177. Pass correct index to function-parameter of .wrap

Changeset: 47c605f693457412a53c9145cafe55420ab8f236

Changed November 06, 2011 10:04PM UTC by dmethvin comment:5

milestone: 1.next1.7.1