Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slidetoggle not working wrong class

I have created a slidetoggle but it's not working. Generrally if I hovered on the year the months will display via slidetoggle but its not working...Probably the class on the script is wrong. Sample fiddle

HTML:

    <div class="smart-archives">

    <ul>
        <a class="year-link" href="http://net/2015">2015</a>: 

        <li><a class="month-link" href="http://.net/2015/01" title="1 post">January</a></li>
        <li><a class="month-link" href="http://.net/2015/02" title="1 post">February</a></li>
        <li><a class="month-link" href="http://.net/2015/03" title="16 posts">March</a></li>
        <li><a class="month-link" href="http://.net/2015/04" title="13 posts">April</a></li>
<li><a class="month-link" href="http://.net/2015/05" title="9 posts">May</a></li>
<li><a class="month-link" href="http://.net/2015/06" title="4 posts">June</a></li>
<li class="empty-month">July</li>
<li class="empty-month">August</li>
<li class="empty-month">September</li>
<li class="empty-month">October</li>
<li class="empty-month">November</li>
<li class="empty-month">December</li>
</ul>

    <ul>
<a class="year-link" href="http://.net/2014">2014</a>:
<li class="empty-month">January</li>
<li><a class="month-link" href="http://.net/2014/02" title="14 posts">February</a></li>
<li><a class="month-link" href="http://.net/2014/03" title="25 posts">March</a></li>
<li><a class="month-link" href="http://.net/2014/04" title="11 posts">April</a></li>
<li><a class="month-link" href="http://.net/2014/05" title="11 posts">May</a></li>
<li><a class="month-link" href="http://.net/2014/06" title="5 posts">June</a></li>
<li><a class="month-link" href="http://.net/2014/07" title="4 posts">July</a></li>
<li><a class="month-link" href="http://.net/2014/08" title="6 posts">August</a></li>
<li><a class="month-link" href="http://.net/2014/09" title="6 posts">September</a></li>
<li><a class="month-link" href="http://.net/2014/10" title="3 posts">October</a></li>
<li><a class="month-link" href="http://.net/2014/11" title="4 posts">November</a></li>
<li><a class="month-link" href="http://.net/2014/12" title="1 post">December</a></li>
</ul>
    </div>

CSS:

ul li { display:none; }
.empty-month { display: none; }

SCRIPT:

$("ul > li").hover(function () {
    $(this).children("ul li").slideToggle("fast");
});
like image 849
MIke Avatar asked Mar 02 '26 13:03

MIke


1 Answers

You should slide toggle sibling lis on hover of anchor as below:

DEMO

$("ul > a").hover(function () {
    $(this).siblings("li").slideToggle("fast");
});

and you might face below problems here if you keep that option on hover

  • It might not work on properly on mobile
  • It will not allow you to click on the months once you hoverout of the link

So What I suggest is do the same functionality on click like

DEMO FOR CLICK

$("ul > a").click(function (e) {
    e.preventDefault();
    $(this).siblings("li").slideToggle("fast");
});
like image 116
Guruprasad J Rao Avatar answered Mar 05 '26 02:03

Guruprasad J Rao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!