Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to stop return false in jQuery from overriding href in HTML
    text
    copied!<p><strong>HTML</strong><br/> I am adding my two links which will send my 'Unanswered' link to my admin controller and my 'Answered' link to a function in my admin controller.</p> <pre><code>&lt;h2 class="unanswered"&gt; &lt;?=anchor('admin/', 'Unanswered', array('class' =&gt; 'selected'))?&gt; &lt;/h2&gt; &lt;h2 class="answered"&gt; &lt;?=anchor('admin/answered_posts', 'Answered')?&gt; &lt;/h2&gt; </code></pre> <p><strong>Jquery</strong><br/> Here I am just trying to add and remove styles to my links. When I keep the return false my styles work fine, but my href in the html anchor no longer runs, so I am not able to get back the posts needed from my controller. When I remove the return false my href works fine and I am getting back what I need from my controller, but my styles that I am adding in my jQuery no longer work.</p> <pre><code>$('.unanswered').click(function(){ $('.answered a').removeClass('active'); $('.unanswered a').addClass('active'); return false; }); $('.answered').click(function(){ $('.unanswered a').removeClass('active'); $('.answered a').addClass('active'); return false; }); </code></pre> <p><strong>Side Note</strong><br/> I have also tried doing:</p> <pre><code>$('.unanswered').click(function(e){ e.preventDefault(); $('.answered a').removeClass('active'); $('.unanswered a').addClass('active'); }); $('.answered').click(function(e){ e.preventDefault(); $('.unanswered a').removeClass('active'); $('.answered a').addClass('active'); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload