admin管理员组文章数量:1425717
I have a hyperlink on my page. I want to show a div when I mouse over the hyperlink, and hide it when I mouseout.
My html:
<a onmouseover="showDiv(this)" onmouseout="hideDiv(this)">
<img>
<div class="inner-block">
Content
</div>
</a>
Javascript:
function showDiv(elem) {
elem.getElementsByTagName("div").style.visibility="visible";
}
function hideDiv(elem) {
elem.getElementsByClassName("inner-block2").style.visibility="hidden";
}
and CSS:
.inner-block {
visibility: hidden
}
I've tried getElementsByTagName, getElementsByClassName, whatever I try I get
Uncaught TypeError: Cannot set property 'visibility' of undefined
I have a hyperlink on my page. I want to show a div when I mouse over the hyperlink, and hide it when I mouseout.
My html:
<a onmouseover="showDiv(this)" onmouseout="hideDiv(this)">
<img>
<div class="inner-block">
Content
</div>
</a>
Javascript:
function showDiv(elem) {
elem.getElementsByTagName("div").style.visibility="visible";
}
function hideDiv(elem) {
elem.getElementsByClassName("inner-block2").style.visibility="hidden";
}
and CSS:
.inner-block {
visibility: hidden
}
I've tried getElementsByTagName, getElementsByClassName, whatever I try I get
Uncaught TypeError: Cannot set property 'visibility' of undefined
Share
Improve this question
asked Aug 14, 2012 at 16:53
codesw1tchcodesw1tch
72011 silver badges30 bronze badges
2
- Is the closing of the a tag after that div? – Mike Brant Commented Aug 14, 2012 at 16:56
- Yes, The closing of the a tag is after the div- – codesw1tch Commented Aug 14, 2012 at 16:57
1 Answer
Reset to default 3try this :
function showDiv(elem) {
elem.getElementsByTagName("div")[0].style.visibility="visible";
}
function hideDiv(elem) {
elem.getElementsByTagName("div")[0].style.visibility = "hidden"
}
since getElementsByClassName("inner-block2") will return NodeList
本文标签: htmlShowhide div onmouseoveronmouseout JavascriptStack Overflow
版权声明:本文标题:html - Showhide div onmouseoveronmouseout Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745416107a2657691.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论