jQuery : remove element except inside element

jQuery has an unwrap() method which removes the parent node and leaves the matched element in place:

$(".gallery").contents().filter(".thumbnail").unwrap();

// or (faster)
$(".gallery .thumbnail").unwrap();

Leave a Comment