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 7978837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:36:00+00:00 2026-06-04T09:36:00+00:00

hey I have this silly issue and I hope you could help me to

  • 0

hey I have this silly issue and I hope you could help me to solve it. I have some “a” elements and I just want to add an active class when clicked.

I tried this :

<a href="javascript:mifunction()"></a>

js:
function mifunction(){
 $(this).addClass('active');
}

but it doesn’t work, so I tried this:

<a></a>

js:
$('a').click(function() {
  $(this).addClass('active');               
});

It doesn’t work either. It just worked when I mixed both. But users have to dubbleclick the element, which is not an option:

<a href="javascript:mifunction()"></a>
js:

function mifunction(){
 $('a').click(function() {
   $(this).addClass('active');              
 });
}

Do you have any idea of how to solve this?

Thank you very much!

  • 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-04T09:36:01+00:00Added an answer on June 4, 2026 at 9:36 am

    It is working here with your 2nd example:


    • Demo

    May be you need to wrap your jQuery code in :

    $(function() {
    
      $('a').click(function() {
         $('a.active').removeClass('active'); // you may also want to remove previous
         $(this).addClass('active');               
      });
    
    });
    

    Also make sure that you included jQuery library path in your HTML:

    <script type="text/javascript" src="/path/jQuery.min.js"></script>
    

    OR:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
    

    EDIT:

    (Links are added dynamically)

    $(function() {
    
      $('a').on( 'click', function() {
         $('a.active').removeClass('active'); // you may also want to remove previous
         $(this).addClass('active');               
      });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I need some help with this: I have two view controllers, let's
Hey guys I simply cannot get this to work. I have some content that
Hey I have this kinda structure in my ini file I want to be
Hey, so basically I have this issue, where I'm trying to put an equation
Hey, I have this code here: ArrayList arrayList = new ArrayList(); arrayList.add(one); arrayList.add(two); arrayList.add(three);
Hey peepz! I have this footer image, that I want to align to the
Hey I'm just learning C in school and I have this idea for a
Hey I have this code that sends an email with some data sent by
If I have this array: array( hey , bla , test); and I want
Possible Duplicate: Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) Hey I have seen this issue a lot

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.