I
I
Ivan Simonov2020-05-11 10:42:17
JavaScript
Ivan Simonov, 2020-05-11 10:42:17

How to create show/hide without using toggle?

Hello
There is a code - fiddle
How to create show/hidewhen clicking on the same button without using toggle?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-05-11
@ivan00007

btn.addEventListener('click', (event) => {
  block.classList.contains('active') ? hide() : show();
});

You can also add an open flag as a variable or data attribute on the element. But it's easier with a class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question