.toggle()

.toggle() Method

  • Method that shows or hides element in such a way that if the element is initially displayed, it will be hidden; if hidden, it will be displayed

Example

$(() => {
  $("button").click(() => {
    // toggle #box element
    $("#box").toggle()
  })
})

JS Bin on jsbin.com