title: Replacing the jQuery .on() method in Vanilla Javascript
body: <p>I’m trying to replace my jQuery with Vanilla Javascript but I’m not able to replicate jQuery’s <code>.on()</code> method for this script ...</p>
  <pre><code>document.querySelectorAll( &quot;nav.subpage button&quot; ).forEach( node =&gt; {
  
      node.addEventListener( &quot;click&quot;, function() {
  
          this.closest( &quot;nav.subpage&quot; ).querySelectorAll( &quot;.current&quot; ).forEach( node =&gt; {
  
              node.classList.remove( &quot;current&quot; );
  
          });
  
          this.closest( &quot;div&quot; ).querySelectorAll( &quot;.wrapper&quot; ).forEach( node =&gt; {
  
              node.style.display = &quot;none&quot;;
  
          });
  
          // =/= c l o s e - b u t t o n
  
          if ( !this.classList.contains( &quot;close&quot; ) ) {
  
              this.classList.add( &quot;current&quot; );
  
              document.getElementById( this.dataset.target ).style.display = &quot;block&quot;;
  
          }
  
      });
  
  });
  </code></pre>
  <p>I need it to make this script work on dynamically added content, too.</p>
  <p>Please help!</p>