ElementWrapper.toggle()
Definition
ts
toggle(): thisDescription
Toggles the visibility of all selected elements.
- If an element is currently visible, it is hidden (its
displayis set tononeand the original value is saved). - If an element is currently hidden, it is shown (the saved
displayvalue is restored, defaulting toblock).
Examples
html
<div class="panel">Panel content</div>ts
$('.panel').toggle(); // Hides the panel
$('.panel').toggle(); // Shows it againToggling on button click
ts
$('#toggle-btn').on('click', () => {
$('.panel').toggle();
});