Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery mouseover not working

The problem is that I only get span element showed when I click on li not when I hover over li!

I have something like:

       <ul class="nav nav-pills nav-stacked">
        @foreach (var category in Model.Categories)  
     {
        <li class="categoryListEl"><a>@category.Name <span      style="float:right;display:none"class="badge badge-important">
<button class="close">&times;</button></span></a></li>
     }
         </ul>

My Jquery code is:

 $(function ()
    {
  $(".categoryListEl").mouseover(function () {
           $this = $(this);
          $this.find("span").css("display", "block");
    });
    $(".categoryListEl").mouseleave(function ()
    {
        $this = $(this);
        $this.find("span").hide();

    });;
 );
like image 584
Vlado Pandžić Avatar asked Oct 18 '25 20:10

Vlado Pandžić


2 Answers

    $(function ()
        {
      $(".categoryListEl").mouseenter(function () {
               $this = $(this);
              $this.find("span").css("display", "block");
        }).mouseleave(function ()
        {
            $this = $(this);
            $this.find("span").hide();

        });
});
like image 197
Chetan Bhopal Avatar answered Oct 20 '25 11:10

Chetan Bhopal


There's some of syntax error in your code. You might try this code, which always works:

$(function () {
    $(".categoryListEl").hover(function () {
        $(this).find("span").toggle();
    });
});

FIDDLE DEMO

like image 30
palaѕн Avatar answered Oct 20 '25 10:10

palaѕн