Bug Tracker

Modify

Ticket #5798 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

replaceWith(function) 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

The context of the callback function is not right when you use replaceWith(function);

$("h3").replaceWith(function(i) {

console.log(this); 'this' will be the next sibling or the parent

});

Because replaceWith(function) ends up delegating to

jQuery(next).before(value) or jQuery(parent).append(value)

Since the current element isn't passed in as an argument or set as the context, there's presently no way to work with it in the callback. I tend to think that the current elem should be set as context, as well as passed in as an arg, to be consistent with .html(function), .text(function), etc.

Change History

comment:1 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.