title: How to plugin anchor tag with jquery
body: <p>I have an existing anchor tag - how do I add a call to a JavaScript function to it, which will run when clicked? I have created pagination dynamically, and would like to call a JavaScript function in the href of the anchor, to both run the function and go to a new page.</p>
  
  <p>Below is an example of the page I would like to display.
  <a href="https://i.stack.imgur.com/jmCgC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jmCgC.png" alt="enter image description here"></a></p>
  
  <p>This is my html code:</p>
  
  <pre><code>&lt;nav aria-label="Page navigation"&gt;
        &lt;ul class="pagination" id="pagination"&gt;
          &lt;?php for ($b=1; $b &lt;= $a ; $b++) {?&gt;
            &lt;li&gt;
            &lt;a class="anchorClass" id="anch" href="&lt;?php echo base_url('attandance/staff_time_depart/'.$depart.'/'.$date_from.'/'.$date_to.'/'.$b) ?&gt;"&gt; &lt;?php echo $b ?&gt; &lt;/a&gt;
            &lt;/li&gt;
          &lt;?php } ?&gt;
        &lt;/ul&gt;
      &lt;/nav&gt;
  </code></pre>
  
  <p>This is my JavaScript code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          var b = '&lt;?php echo $b; ?&gt;';
          var a_href = $("#anch").attr("href");
          $(function () {
              window.pagObj = $('#pagination').twbsPagination({
                  totalPages: b,
                  visiblePages: 5,
                  href: 'true',
                  // anchorClass: a_herf,
                  onPageClick: function (event, page) {
                      console.info(page + ' (from options)');
                  }
              }).on('page', function (event, page) {
                  console.info(page + ' (from event listening)');
              });
          });
      &lt;/script&gt;
  </code></pre>