To trigger Gumby2 Modal switch from JavaScript just add the ‘active’ class to the modal window.

jQuery(document).ready(function($) {

    $('.modal#modal-id').addClass('active');

});

My initial thoughts was this way as it’s better programming to use the event handlers for the triggers so it follows the full functionality (it might have other things that it does not just add active to the main modal container). The Gumby2 documentation on switches and toggles is lacking lots of useful code snippets like this.

jQuery(document).ready(function($) {

    $('.modal .switch[gumby-trigger="|#modal-id"]:first').trigger(Gumby.click);

});

Related Posts:

Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.


No Reader comments

Learn JavaScript for free!
Free course: Introduction to JavaScript

Yours when you take up a free 14-day SitePoint Premium trial.