Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:49:40+00:00 2026-06-18T05:49:40+00:00

HTML I am adding my two links which will send my ‘Unanswered’ link to

  • 0

HTML
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.

<h2 class="unanswered">
   <?=anchor('admin/', 'Unanswered', array('class' => 'selected'))?>
</h2>

<h2 class="answered">
   <?=anchor('admin/answered_posts', 'Answered')?>
</h2>

Jquery
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.

$('.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;
     });

Side Note
I have also tried doing:

$('.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');
     });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:49:41+00:00Added an answer on June 18, 2026 at 5:49 am

    I’d refer to the comments on the question – if I understand your intent (click a link, update something behind the scenes on the server, and apply a style on the page without reloading the page) this is probably something you’d want to do with AJAX. For example (untested code):

    $('.unanswered, .answered').click(function() {
        $.ajax({
            url: $(this).attr('href')
        }).done(function() {
            /* You'll need to add some logic in here to remove the active class from
            the answered or unanswered question if it exists. Depending on the rest of your 
            HTML, this could be done with something like $(this).closest('myWrapper').find('a.active').removeClass('active') */
    
            /* Once you've cleaned up any active classes, add an active class to this element */
            $(this).addClass('active');
    
        });
    });
    

    More reading on jQuery AJAX here: http://api.jquery.com/jQuery.ajax/

    Since I don’t understand exactly what you’re attempting to do, you can also try this (which will update the class, then submit the request). You may not see the CSS changes reflected since the page will reload quickly.

    $('.answered').click(function() {
       // Set up the classes here
       $('.unanswered a').removeClass('active');
       $(this).addClass('active');
    
       /* When this element has an active class, then it will redirect to the link's URL, the HREF attribute. We do this check because javascript is asynchronous, all lines can run at the same time, so this prevents window.location from being called before the class is changed */
       if($(this).hasClass('active')) {
           window.location = $(this).attr('href');
       }
    
       // Still return false to prevent the default redirect that would happen without javascript.
       return false;
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function in jquery which displays images on link click and also
I have a controller which accepts URLs in the following two formats: Network/AddOrEdit ->
I'm adding HTML controls dynamically using java script. For instance, I have one button
i have animated div in html. it is adding 1px to div in every
//html structure <div id='outer'> <div id='inner'> </div> </div> I am adding some data to
this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html , the home of rubyinline, adding/moding as indicated in
How do you get children of primary links to output in the HTML? Only
Using jQuery, I can highlight a single HTML element by adding css to the
Let's say that I have two html pages that are identically designed, but have
I have a wordpress page which has two loops like so... <?php global $post;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.