Wordy Jquery toggle

Well if you prefer maintaining a c&p job over 4 LOC… ^^ anyway to answer your other question, try

$('#btnbag1a').click(function(event) {
  event.preventDefault()
  $('#bag1a').toggle()
})

On another note, you might actually link to the elements in questions, like

<a id="btnbag1a" class="light-blue btn" href="#bag1a">Show/Hide Parts</a>

The JS might thus become

$('#btnbag1a').click(function(event) {
  event.preventDefault()
  $('#' + this.href).toggle()
})

… and with the following CSS…

#bag1a:target {
  display: block;
}

… it will still get you to (and show) the corresponding element if JS is disabled. (This one was for @felgall…)

1 Like