views:

455

answers:

1

Hi all, 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 fine. But how would i programmatically trigger the toggle instead of clicking on it?

+3  A: 

Like this:

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

Since toggle is just functions that are swapped and executed on a click, that's what you want to trigger. Also available is the shortcut:

$('.access a').click(); //Same as first method
Nick Craver