replaceWith confusing behaviour with a jQuery set

// jQuery 2.2.2

var set = $('<p></p><b></b><i></i>');
set.filter('b').replaceWith('<a></a>');
console.log( set );

I would expect <b> to be changed to an <a> element, but that is not the case.

How can one replace an element if not by using filter then replaceWith ?
Since filter creates a new jQuery Object, this creates a problem.

Sadly, this seems the awkward way of doing such a simple thing:
http://stackoverflow.com/a/36289638/104380

I suggest updating the API with some kind of a way to do such a replace more easily

Author: Fantashit

1 thought on “replaceWith confusing behaviour with a jQuery set

Comments are closed.