Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created December 16, 2022 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/4c9aea28c6a915c141d784a7ae661ff5 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/4c9aea28c6a915c141d784a7ae661ff5 to your computer and use it in GitHub Desktop.
Click This to Click That
//Replace .trigger with the class that gets clicked and .recipient with the class that should receive the click.
$('.trigger').on('click', function(evt) {
setTimeout(function() {
$('.recipient').triggerHandler('click'); //element js will click
}, 500); //ms of time before action
});
//Another related approach with a scroll function that can move content in a parent element with overflow:scroll/auto set.
$('.trigger').on('click', function(evt) {
setTimeout(function() {
$('.recipient').triggerHandler('click');
$('.overflow-scroll').scrollLeft(150); //scroll this element
$('html, body').animate({
scrollTop: $("#main").offset().top
}, 1000); //anchor link to a specific ID
}, 500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment