简体   繁体   中英

trigger function on Button doesn't work

My Jquery code won't trigger function when simulating button click.

HTML:

<section id="latz-secondItem">
     <button type="button" data-role="none" class="slick-prev" style="display:   
           block;">Previous</button>
     <button type="button" data-role="none" class="slick-next" style="display:  
           block;">Next</button>
</section>

Jquery:

/* link directly to the 2nd slide */
var hashTag = window.location.hash;
if (hashTag != '' && hashTag == '#latz-secondItem') {               
    setTimeout(function(){
        $('html, body').animate({
            'scrollTop': $('#latz-secondItem').offset().top
        }, 2000);
     },2000);
     $('#latz-secondItem .slick-next').trigger('click');
}

Register callback for click event like this

$(function(){
    $(".slick-next").on("click", function(){
         // code to be executed on click
    })
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM