jQuery删除div的任一侧的标签
如何删除此div之外的p标签(我不想删除测试div)。
content here
我想要的结果是……
content here
我知道这里有一个类似的问题: jQuery:如何删除周围的div标签? ,但没有让它在我的情况下工作
我试过了
$('p .test').replaceWith($('.test));
但当然,只选择沙龙幻灯片div,而不是之前的p。
这样做但是请记住它会影响所有具有class="test"
div
$("div.test").unwrap();
您正在寻找的方法叫做.unwrap()
查看文档: http : .unwrap()
请尝试以下方法:
$('.salon-slideshow').each(function() { $(this).parent().replaceWith($(this)); });
试试这个:
$('.test').each(function() { $(this).insertAfter($(this).parent()); $(this).prev().remove(); });