开发者

javascript dom td href

How can I get the href url from in the td with dom

<td class="left"><a href="index.php&del=3" oncli开发者_开发知识库ck="return confirmnDelete()"><img src="delete.png" style="border: none"/></a></td>


Not really enough info given, but:

alert(document.getElementById("theTable").rows[0].cells[0].firstChild.href);

http://jsfiddle.net/QaKmx/1


It'd be helpful if you had an ID assigned to that anchor, but if you want to make no changes to markup:

var allCells = document.getElementByTagName("TD");
for(var i = 0; i < allCells.length; i++){
     if(allCells[i].className == "left"){
          if(allCells[i].firstChild && allCells[i].firstChild.tagName.toLowerCase() == "a"){
     if(allCells[i].firstChild.onclick.toString().replace("return confirmDelete()", "") != allCells[i].firstChild.onclick.toString()){
     return allCells[i].firstChild.href;
}
     }
}


Are you able to use a dom manipulation library such as jquery? If so, then something like:

$('.left > a').click(function(e) {
    e.preventDefault();
    var url = $(this).attr('href');
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜