javascript - jQuery Hover event is not bound to the child element -


i bind hover event li tag(see code below or fiddle, code details), i.e. when hover on li, added class changes background of li.

li tag having 1 a tag encloses 2 span tags texts, when hover on 2 text span tags, not seeing hover event executed. please see fiddle http://jsfiddle.net/shmdhussain/jbvmv/ . in advance help.

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>      <title>untitled page</title>      <link rel="stylesheet" type="text/css" href="css/reset.css"></link>      <link rel="stylesheet" type="text/css"  href="css/mystyle.css"></link>       <script src="/jquery-my.js" ></script>     <script>         jquery(function($){             var grouptab = $("ul").children("li");               grouptab.hover(function(){             if(!($(this).children("a").hasclass("current")))             {                 $(this).siblings("li").children("a").removeclass("hoverbg");                             $(this).children("a").addclass("hoverbg");             }                                });                      grouptab.mouseout(function(){                 $(this).children("a").removeclass("hoverbg");                            });         });      </script>     <style>         li{background-color:#dcdedb;             border:1px solid black;             padding:20px;         }         .hoverbg{             background-color:red;         }     </style>  </head>  <body>      <div class="">             <ul class="" id="">                     <li class=" ">                         <a class="current" href="#" >                             <span class="">                                 myname                             </span>                             <br>                             <span class="">mydata</span>                         </a>                     </li>                     <li class="" >                         <a class="" href="#" >                             <span class="">                                 myname                             </span>                             <br>                             <span class="">mydata</span>                         </a>                     </li>                     <li class="" >                         <a class="" href="#">                             <span class="">                                 myname                             </span>                             <br>                             <span class="">mydata</span>                         </a>                     </li>             </ul>   </div> </body>   </html> 

the .hover() jquery function takes 2 arguments, function executed @ hover (mouseenter) , function executed @ hover out (mouseleave). should use instead of mouseleave

grouptab.hover(function () {         if (!($(this).children("a").hasclass("current"))) {             $(this).siblings("li").children("a").removeclass("hoverbg");             $(this).children("a").addclass("hoverbg");         }     }, function () {         $(this).children("a").removeclass("hoverbg");     }); 

demo


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -