www.webdeveloper.com
Results 1 to 3 of 3

Thread: onmouseover event

  1. #1
    Join Date
    Oct 2011
    Posts
    4

    onmouseover event

    Why does this code not produce a dropdown list when onmouseover happens?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
    <html>

    <head>
    <style type="text/css">

    div.dg
    {

    border:2px solid white;
    display:none;
    }



    a
    {
    width: 100px;
    text-align:center;
    background-color:red;
    color:white;
    font-size:16px;
    display:block;

    }


    </style>


    </head>

    <body>

    <div>
    <a id="kj" href="kkjklj.com" onmouseover="this.parentNode.childNodes[1].style.display='inline';"
    onmouseout="this.parentNode.childNodes[1].style.display='none';">kjlj</a>
    <div class="dg">
    <a href="kjlj.com">lkjefee</a>
    <a href="ehfueh.com">fheufheuih</a>
    </div>
    </div>




    </body>
    </html>

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    1. childNodes[] is inconsistent among browsers. Some browsers, like Mozilla, count all the possible text nodes (the "gaps" between the tags) as childNodes, others, like IE, count only some of them or none. As a result childNodes[1] might designate different elements, according to the browser. Use getElementsByTagName() instead.

    2. A DIV element is a block level element, thus it can not have the display inline. You should use the value: block

    Is this what you want?
    Code:
    <div>
    <a id="kj" href="kkjklj.com" onmouseover="this.parentNode.getElementsByTagName('div')[0].style.display='block';"
    onmouseout="this.parentNode.getElementsByTagName('div')[0].style.display='none';">kjlj</a>
    <div class="dg">
    <a href="kjlj.com">lkjefee</a>
    <a href="ehfueh.com">fheufheuih</a>
    </div>
    </div>
    Last edited by Kor; 10-18-2011 at 03:05 AM.

  3. #3
    Join Date
    Oct 2011
    Posts
    4
    i didn't know that, thank you very much. Yes that is the code i was trying to write!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles