function fixHrefTarget(container, tgtClass = ":is-target") {
  const linksWithHash = container.querySelectorAll('a[href^="#"]')
  let target = undefined

  function add(tgt, klass) { tgt.classList.add(klass) }
  function rm(tgt, klass) { tgt.classList.remove(klass) }

  linksWithHash.forEach((link) => {
    link.addEventListener(pointerClick, function(e) {
      e.preventDefault()

      // set new target
      var newTgt = this.getAttribute("href")
      if (newTgt != "#") {
        target = container.querySelector(newTgt)

        // remove or add new class
        if(target.classList.contains(tgtClass)) rm(target, tgtClass)
        else add(target, tgtClass)
      }
    })
  })
}
/**
 * fixHrefTarget
 *  Mimics :target behaviour using class toggling.
 *  in CSS use :is-target, instead of :target
 */
fixHrefTarget
Mimics :target behaviour using class toggling.
in CSS use :is-target, instead of :target
fixHrefTarget Mimics : target behaviour using class toggling . in CSS use : is - target instead of : target
function fixHrefTarget(container, tgtClass = ":is-target") {
  const linksWithHash = container.querySelectorAll('a[href^="#"]')
  let target = undefined
  function add(tgt, klass) { tgt.classList.add(klass) }
  function rm(tgt, klass) { tgt.classList.remove(klass) }
  linksWithHash.forEach((link) => {
    link.addEventListener(pointerClick, function(e) {
      e.preventDefault()
      var newTgt = this.getAttribute("href")
      if (newTgt != "#") {
        target = container.querySelector(newTgt)
        if(target.classList.contains(tgtClass)) rm(target, tgtClass)
        else add(target, tgtClass)
      }
    })
  })
}
function fixHrefTarget ( container , tgtClass = ":is-target" ) { const linksWithHash = container . querySelectorAll ( 'a[href^="#"]' ) let target = undefined function add ( tgt , klass ) { tgt . classList . add ( klass ) } function rm ( tgt , klass ) { tgt . classList . remove ( klass ) } linksWithHash . forEach ( ( link ) => { link . addEventListener ( pointerClick , function ( e ) { e . preventDefault ( ) var newTgt = this . getAttribute ( "href" ) if ( newTgt != "#" ) { target = container . querySelector ( newTgt ) if ( target . classList . contains ( tgtClass ) ) rm ( target , tgtClass ) else add ( target , tgtClass ) } } ) } ) }
fixHrefTarget
  Mimics :target behaviour using class toggling.
fixHrefTarget Mimics : target behaviour using class toggling .
// set new target // remove or add new class