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();
  • http://api.jquery.com/unwrap/

$(".thumbnail").unwrap()

http://api.jquery.com/unwrap/