通过jQuery删除未关闭的标记元素

Tar*_*rik 1 html javascript jquery

说我有如下元素序列:

<div style="margin-bottom:9px;line-height:normal;margin-top:4px"></div>
<div style="margin-bottom:9px;line-height:normal;margin-top:4px">Something Here</div>
<div style="margin-bottom:9px;line-height:normal;margin-top:4px">
Run Code Online (Sandbox Code Playgroud)

下面有未公开的元素,我想删除它们,因为它们破坏了设计布局.那么请告诉我如何查找和删除上面未封闭和空的元素:

<div style="margin-bottom:9px;line-height:normal;margin-top:4px"></div>
<div style="margin-bottom:9px;line-height:normal;margin-top:4px">
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助.

编辑推荐:首先,编辑源代码是不可能的.因为它们是像这样的百页,我需要一个快速的解决方案:(我没有写那些代码,但我现在必须维护,我需要临时但工作的解决方案.他们是静态的所以我不能使用服务器端此时的代码因为它们都是html文件.

编辑建议2: 结构实际上是相同的.

HTML损坏:

<div style="margin-bottom:9px;line-height:normal;margin-top:4px"></div>
<div style="margin-bottom:9px;line-height:normal;margin-top:4px">Something Here</div>
<div style="margin-bottom:9px;line-height:normal;margin-top:4px">
<div style="margin-bottom:9px;line-height:normal;margin-top:4px"></div>
<div style="margin-bottom:9px;line-height:normal;margin-top:4px">Something Here</div>
<div style="margin-bottom:9px;line-height:normal;margin-top:4px">
Run Code Online (Sandbox Code Playgroud)

它应该如何:

<div style="margin-bottom:9px;line-height:normal;margin-top:4px">Something Here</div>
<div style="margin-bottom:9px;line-height:normal;margin-top:4px">Something Here</div>
Run Code Online (Sandbox Code Playgroud)

没有内在的div或其他任何东西,它非常简单.

Dan*_*ite 5

JQuery不操纵XML/HTML结构,只操纵DOM和DOM的表示.我相信JQuery不可能做那样的事情.

最好的办法是通过W3C验证器运行您的页面.