【发布时间】:2018-05-24 03:11:23
【问题描述】:
我需要使用 Javascript 删除一个 div 中所有带有“item”类的标签,除了一个标签 <b> 标签。
这是我的 HTML 文档的样子,(我的示例代码):
<div class="item">
<a href="sample-href1">
<div class="result-image">
<h5 class="result-cat cat-conf wn">test</h5>
</div>
</a>
<h4>1.
<a href="sample-href2" title="sample-title2">
<b> goal tag1 (i need just this tag) </b>
</a>
</h4>
<span class="feature">test</span>
<div class="compact">
</br>
<a href="test12" title="test12"> test12 </a>
<br>
<b> some text </b>
<a href="test123" title="test123"> test123 </a> -
<a href="test147" title="test147" > test147 </a>
</br>
<b>11</b>
another some text
</br>
</div>
<a href="test159" title="test159" class="download"> test </a>
<div class="clr"></div>
</div>
<div class="item">
<a href="sample-href1968">
<div class="result-image">
<h5 class="result-cat cat-conf wn">test418</h5>
</div>
</a>
<h4>2.
<a href="sample-href215" title="sample-title215">
<b> goal tag2 (i need just this tag) </b>
</a>
</h4>
<span class="feature">test23</span>
<div class="compact">
</br>
<a href="test12234" title="test12234"> test12234 </a>
<br>
<b> some text </b>
<a href="test12233" title="test12233"> test12233 </a> -
<a href="test14657" title="test14657" > test14657 </a>
</br>
<b>16</b>
another some text
</br>
</div>
<a href="test15912" title="test15912" class="download"> test </a>
<div class="clr"></div>
</div>
... (and so on (<div class=item> ... </div>))
我只需要这个标签<b> goad tag(1, 2, ...) (i need just this tag) </b>,我想用javascript删除这个标签<div class=item> ... </div>之前和之后的所有标签。
注意:我在源文件(test.html)中有很多 div(<div class=item> ... </div>),我想在加载页面时有这样的内容:
<div class=item>
<b> goal tag1 (i need just this tag) </b>
</div>
<div class=item>
<b> goal tag1 (i need just this tag) </b>
</div>
...
我对 Javascript 非常陌生,谁能帮我解决这个问题?
【问题讨论】:
标签: javascript html