javascript - Why jquery trigger doesn't work? -


this part should trigger click on image when #x present in browser url... never happens....

// var hash = window.location.hash.slice(1); if (hash) {     $("#barely_slide img[data-imgnum='"+ hash +"']").trigger("click"); } else {     move_slide(); } 

actuall part needs triggered:

// $("#barely_slide article img").on("click", function(){     if ($(this).attr("class") == "focus") {return false;}     //         $("#barely_slide article img").removeclass("previous");         $("#barely_slide article .focus").addclass("previous");         var image = $(this); $(".previous").animate({"height":300,"margin-top":0}, "fast");     $("#barely_slide article .focus").removeclass("focus");     image.addclass("focus");     //         window.location.hash = image.attr("data-imgnum");     //     move_slide();     return false; }); 

remember attach click handler before trigger it:

$("#barely_slide article img").on("click", function() { // attach click handler   ... }); 

trigger (this must come after above):

$("#barely_slide img[data-imgnum='"+ hash +"']").trigger("click"); // or .click() 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -