为什么.parent
中某个项的.getElementsByTagName
返回undefined?我正在尝试将一个类应用于href
等于document.URL
的父级。
<div id="JSE_vertical_nav">
<div class="jse_link_row">
<a href="../SitePages/Home.aspx">HOME</a>
</div>
<div class="jse_link_row">
<a href="#">ABOUT</a>
</div>
<div class="jse_link_row">
<a href="#">NEWS</a>
</div>
</div>
<script language="javascript" type="text/javascript">
var jse_page_url = document.URL;
var jse_links_in_nav = document.getElementById('JSE_vertical_nav').getElementsByTagName('a');
for (var i=0; i < jse_links_in_nav.length; i++) {
if (jse_links_in_nav[i] == jse_page_url) {
//why does this alert undefined?
alert(jse_links_in_nav[i].parent);
}
}
</script>
答案 0 :(得分:3)
parentNode
是您正在寻找的财产:)
答案 1 :(得分:0)
使用jquery
$(document).ready(function(){
if($('a[href="google.com"]').length != 0)
{
alert("found !");
}
});