少说这是我的div:
<div id="success">
<a href="/index.php">link1</a>
<a href="/index.php">!AnotherLink!</a>
<a href="cat.php">link3</a>
</div>
我想删除成功div中的任何链接,即相同的“href”
应该是这样的:
<div id="success">
<a href="/index.php">link1</a>
<a href="cat.php">link3</a>
</div>
答案 0 :(得分:2)
这应该有效:
function removeDups() {
var container = document.getElementById("success");
var a = container.getElementsByTagName("a");
var hrefs = {};
for (var i = 0; i < a.length; i++) {
if (a[i].href in hrefs) {
a[i].parentNode.removeChild(a[i]);
} else {
hrefs[a[i].href] = 1;
}
}
}