CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Javascript show/hide on mouseover div (http://www.codingforums.com/showthread.php?t=250711)

Juniper747 02-05-2012 05:07 AM

Javascript show/hide on mouseover div
 
Hi I am trying to implement a hide/show div, such that when you mouse over a div, another div pop's up below it. Here's what I have so far, but for some reason, only the first div set is working. That is when I mouse over div 1, div 2 shows up. So why isnt it working for divs 3,4 and 5,6? Here's my code:

Code:

           
HTML
          <div >
                <div id="showhide">
                    Line 1
                </div>
                <div id="visiblediv" style="display: none;">
                    Line 2
                </div>
            </div>
            <div >
                <div id="showhide">
                    Line 3
                </div>
                <div id="visiblediv" style="display: none;">
                    Line 4
                </div>
            </div>
            <div >
                <div id="showhide">
                    Line 5
                </div>
                <div id="visiblediv" style="display: none;">
                    Line 6
                </div>
            </div>
 
Javascript:
<script>
        function mover(){
document.getElementById("visiblediv").style.display="block"
        }
        function mout() {               
document.getElementById("visiblediv").style.display="none"
        }
document.getElementById('showhide').onmouseover=mover;
document.getElementById('showhide').onmouseout=mout;
</script>                       

CSS:
#visiblediv {
        visibility:visible;
        border:1px dotted black;
}

Any ideas, as to why it's not working?

Old Pedant 02-05-2012 07:02 AM

You can *NOT* use the same ID for more than one element on a page.

The fact that your code works even for the first such <div> is just luck: You happened to choose a browser that ignores all but the first such ID. Other browsers wouldn't have worked at all.

Juniper747 02-05-2012 07:08 AM

Ok... thanks. Know any other ways I could implement what I'm trying to do?

myth024 10-31-2012 11:27 PM

Quote:

Originally Posted by Juniper747 (Post 1189300)
Ok... thanks. Know any other ways I could implement what I'm trying to do?

maybe getElementbyClass

felgall 11-01-2012 02:17 AM

Quote:

Originally Posted by myth024 (Post 1287331)
maybe getElementbyClass

you mean getElementsByClassName


All times are GMT +1. The time now is 08:05 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.