html - Showhide div onmouseoveronmouseout Javascript - Stack Overflow

I have a hyperlink on my page.I want to show a div when I mouse over the hyperlink, and hide it when

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
Add a ment  | 

1 Answer 1

Reset to default 3

try 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745416107a4626755.html

相关推荐

  • html - Showhide div onmouseoveronmouseout Javascript - Stack Overflow

    I have a hyperlink on my page.I want to show a div when I mouse over the hyperlink, and hide it when

    7小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信