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?
The toggle() method toggles between hide() and show() for the selected elements. This method checks the selected elements for visibility. show() is run if an element is hidden. hide() is run if an element is visible - This creates a toggle effect.
The toggle() method attaches two or more functions to toggle between for the click event for the selected elements. When clicking on an element, the first specified function fires, when clicking again, the second function fires, and so on. Note: There is also a jQuery Effects method called toggle().
click(function() { $("input[name=recipients\\[\\]]"). attr('checked', true); }); });
jQuery | toggle() Method The toggle() method is used to check the visibility of selected elements to toggle between hide() and show() for the selected elements. show() is run when the element is hidden.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With