Bug Tracker

Modify

Ticket #5799 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

wrapInner(function): inconsistent with wrapInner(html), callback scope is broken

Reported by: ajpiano Owned by:
Priority: major Milestone: 1.4.1
Component: core Version: 1.4
Keywords: Cc:
Blocking: Blocked by:

Description

wrapInner(function) does not have the same effect on an element as wrapInner(html), etc. Each of the first-child elements - including textnodess - gets wrapped individually, rather than, as intended, wrapping the contents into a single element.

As, wrapInner is a shortcut to $(elem).contents().wrapAll(fn), the contents get wrapped, one-by-one, by the beginning of $.fn.wrapAll(); This leads to the wrapInner(fn) callback being executed once for every child element, with the child element as 'this'.

 http://jsfiddle.net/ZtBZ2/

<h3>foo<span>bar</span><div>baz</div>bam</h3> <br/> <h3>foo<span>bar</span><div>baz</div>bam</h3>

$("h3:first").wrapInner(function(i) {

console.log(this); return "<strong style='display:block;border:1px solid #000'/>";

}); $("h3:eq(1)").wrapInner("<strong style='display:block;border:1px solid #000'/>");

Attachments

wrapInner.html Download (909 bytes) - added by ajpiano 2 years ago.
wrapInner.2.html Download (909 bytes) - added by ajpiano 2 years ago.

Change History

Changed 2 years ago by ajpiano

comment:1 Changed 2 years ago by ajpiano

the attachment is the same file twice, i accidentally double clicked and it uploaded two copies.

comment:2 Changed 2 years ago by john

  • Status changed from new to closed
  • Resolution set to fixed
  • Component changed from unfilled to core

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.