Bug Tracker

Modify

Ticket #10177 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

index of callback function in .wrap is always 0

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

Description

I have the following HTML: <div class="box">...</div> <div class="box">...</div>

Using the following:

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

I expect to get:

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

Error, I get always 0 for index:

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

The follwing workaround produces the expected result:

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

Change History

comment:1 Changed 3 years ago by timmywil

  • Owner set to manuel@…
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to manipulation

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:  http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 3 years ago by manuel@…

  • Status changed from pending to new

Here is the link to the test using jQuery edge in jsFiddle:  http://jsfiddle.net/8SZAx/2/ showing the bug.

Here is the link to the work around with the expected result:  http://jsfiddle.net/LBbrn/1/

comment:3 Changed 3 years ago by rwaldron

  • Owner changed from manuel@… to rwaldron
  • Priority changed from low to high
  • Status changed from new to assigned
  • Milestone changed from None to 1.next

comment:4 Changed 2 years ago by Toby Brain

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: 47c605f693457412a53c9145cafe55420ab8f236

comment:5 Changed 2 years ago by dmethvin

  • Milestone changed from 1.next to 1.7.1

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.