JQuery Toggle Button Trigger

I have this code:

$('.access a').toggle(function() {
    $('link').attr('href', 'styles/accessstyles.css');
    $('body').css('font-size', '16px');
}, function() {
    $('link').attr('href', 'styles/styles.css');
    $('body').css('font-size', text_sizes[text_current_size] + 'px');
});

It works great. But how would I programmatically launch a switch instead of clicking on it?

+5
source share
1 answer

Like this:

$('.access a').trigger('click');

Since switching is just functions that change and are executed by clicking, what you want to call. Shortcut also available:

$('.access a').click(); //Same as first method
+11
source

All Articles