Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript click event nor working for mobile

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #193998
    femkreations
    Participant

    I wrote a jquery function to open/close left nav as below. How can I make this work for mobile devices?

    Thanks in advance,
    FP

    $(".facetParent > a").on("click", function(e){
            if($(this).parent().has("div")) {
                e.preventDefault();
            }
            if(!$(this).hasClass("active")) {
                // hide any open menus and remove all other classes
                $(".facetParent div").slideUp(300);
                $(".facetParent a").removeClass("active");
    
           // open our new menu and add the open class
            $(this).next("div").slideDown(300);
            $(this).addClass("active");
        }
    
        else if($(this).hasClass("active")) {
            $(this).removeClass("active");
            $(this).next("div").slideUp(300);
        }
    });  
    
    #194003
    Shikkediel
    Participant

    I think it would suffice to change .on("click" into .on("mousedown touchstart". A mobile click is a chaining of touchstart-touchend, the latter is disabled in the script by e.preventDefault() (is my guess).

    #194021
    femkreations
    Participant

    Thanks much. Will check it out.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.