我的HTML
<div class="wrapper">
<div class="wrapper2">
<div class="real_content"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
题
有没有办法让我删除2个div,<div class="real_content"></div>所以它不会出现在我的网站的HTML和前端?谢谢.
你可以试试.replaceWith()(docs):
$('.wrapper').replaceWith( $('.real_content') );
Run Code Online (Sandbox Code Playgroud)
还有一个.unwrap()函数(docs),如果你更喜欢更相对的方式:
$('.real_content').unwrap().unwrap();
Run Code Online (Sandbox Code Playgroud)