javascript从div中删除链接(如果href存在)

javascript从div中删除链接(如果href存在),javascript,html,Javascript,Html,以免说这是我的部门: <div id="success"> <a href="/index.php">link1</a> <a href="/index.php">!AnotherLink!</a> <a href="cat.php">link3</a> </div> 我想删除success div中的任何链接,该链接是相同的“href” 应该是这样的: <div id="success"

以免说这是我的部门:

<div id="success">
<a href="/index.php">link1</a>
<a href="/index.php">!AnotherLink!</a>
<a href="cat.php">link3</a>
</div>

我想删除success div中的任何链接,该链接是相同的“href”

应该是这样的:

<div id="success">
<a href="/index.php">link1</a>
<a href="cat.php">link3</a>
</div>

这应该可以:

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;
        }
    }
}
函数removeDups(){
var container=document.getElementById(“成功”);
var a=container.getElementsByTagName(“a”);
var hrefs={};
对于(变量i=0;i