murach_js_3e/book_apps/ch06/faqs/main.js
// the event handler for the click event of each h2 element
the event handler for the click event of each h2 element
the event handler for the click event of each h2 element
function toggle(e) {
  e.preventDefault();
  const h2 = this; 
  const div = h2.nextElementSibling; 
  if (h2.hasAttribute('class')) {
    h2.removeAttribute('class');
  } else {
    h2.setAttribute('class', 'minus');
  }
  if (div.hasAttribute('class')) {
    div.removeAttribute('class');
  } else {
    div.setAttribute('class', 'open');
  }
}
function toggle ( e ) { e . preventDefault ( ) ; const h2 = this ; const div = h2 . nextElementSibling ; if ( h2 . hasAttribute ( 'class' ) ) { h2 . removeAttribute ( 'class' ) ; } else { h2 . setAttribute ( 'class' , 'minus' ) ; } if ( div . hasAttribute ( 'class' ) ) { div . removeAttribute ( 'class' ) ; } else { div . setAttribute ( 'class' , 'open' ) ; } }
the event handler for the click event of each h2 element
the event handler for the click event of each h2 element
// clicked h2 tag // h2 tag's sibling div tag // toggle plus and minus image in h2 elements by adding or removing a class // toggle div visibility by adding or removing a class