Toggle an Element

To toggle an element, you change the display property of the style object:

  function toggle(el) {
      const display = el.style.display;
      el.style.display = display === 'none' ? 'block' : 'none';
  }Code language: JavaScript (javascript)
Was this tutorial helpful ?