skip to Main Content

while applying slideToggle function the links are not working. below is the link for my demo site.

http://codezigns.com/teyseer_laboratory/htm/toggle.html

my script is

$(".nav li > a").click(function(e) {
        $(this).parent().siblings().find('ul').slideUp(500);
        $(this).next('ul').stop().slideToggle(300);
        return false;
    });

and also include

$(".trigger").click(function(e) {
        e.preventDefault();
        $(".main-nav > ul").slideToggle(300);
    });

Link is applied in parent item “Tutorial” and child item “Photoshop”.

3

Answers


  1. Remove return false; from your a click event. It is preventing redirection.

    Login or Signup to reply.
  2. This is happening because you are returning false on a click event, you should exclude the links from returning false, you should add a class to the real links and exclude them of your function:

    HTML

    <nav class="nav">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Tutorials</a>
                <ul>
                    <li><a class="reallink" href="https://www.google.co.in/">Photoshop</a></li>
                    <li><a href="#">Illustrator</a></li>
                    <li><a href="#">Web Design</a></li>
                </ul>
            </li>
            <li><a href="#">Articles</a></li>
            <li><a href="#">Inspiration</a></li>
        </ul>
    </nav>
    

    JS:

       $(".nav li > a:not(.reallink)").click(function(e) {
            $(this).parent().siblings().find('ul').slideUp(500);
            $(this).next('ul').stop().slideToggle(300);
            return false;
        });
    

    Hope it helps

    Login or Signup to reply.
  3. The problem is you are returning false for each a click. Try like following. Hope this will help you.

    $(".nav li > a").click(function (e) {
        if(this.href.indexOf('#') > -1) {
            $(this).parent().siblings().find('ul').slideUp(500);
            $(this).next('ul').stop().slideToggle(300);
            return false;
        }
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search