Skip to main content

Trigger Gumby2 Modal Swicth from JavaScript

By Sam Deering

JavaScript

Share:

Free JavaScript Book!

Write powerful, clean and maintainable JavaScript.

RRP $11.95

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 has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

New books out now!

Get practical advice to start your career in programming!


Master complex transitions, transformations and animations in CSS!