This is actually a rather useful method, and would probably be even better server-side. It would simplify a lot of things server-side. It has been part of jQuery since 1.0, with the callback equivalent since 1.4.
$.wrap is definitely missing
PRs welcome :)
Is anybody working on this? I would like to take a crack at it.
@dandlezzz Go for it!
A couple of my utility functions for cheerio - feel free to make them into proper methods ;-)
function wrap(selector, wrapper) {
return $(selector).each(function() {
$(this).before(wrapper).prev().append(this);
});
}
function unWrap(selector) {
$(selector).each(function() {
var $this = $(this);
$(this).after($this.contents()).remove();
});
}
function wrapAll(selector, wrapper) {
$(selector).first().before(wrapper).prev().append(selector);
}
A couple of my utility functions for cheerio - feel free to make them into proper methods ;-)
function wrap(selector, wrapper) { return $(selector).each(function() { $(this).before(wrapper).prev().append(this); }); } function unWrap(selector) { $(selector).each(function() { var $this = $(this); $(this).after($this.contents()).remove(); }); } function wrapAll(selector, wrapper) { $(selector).first().before(wrapper).prev().append(selector); }
Very helpful, thank you
Most helpful comment
A couple of my utility functions for cheerio - feel free to make them into proper methods ;-)