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[te开发者_开发问答xt_current_size] + 'px');
});
It works fine. But how would i programmatically trigger the toggle instead of clicking on it?
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
精彩评论