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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:27:13+00:00 2026-06-13T22:27:13+00:00

I have created 2 anchor tag and then i created a function in which

  • 0

I have created 2 anchor tag and then i created a function in which if you click the 1st anchor tag a new class will added to the 2nd one and after that when you click on the second anchor tag it will show a alert, in which its shows the text of the anchor tag with added class. But its not working for me.

Here is the code for your reference:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Title</title>
    <script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script>
    <style type="text/css">
        .highlight{background-color:yellow;}
    </style>
    <script>
        $(function(){
            $("a:eq(0)").click(function(){
                $("a:eq(1)").addClass("highlight");
            });

            $("a.highlight").click(function(){
                alert($(this).text());
            });
        });
    </script>
</head>
<body>
    <a href="#">first</a>
    <a href="#">second</a>
</body>
  • 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-13T22:27:15+00:00Added an answer on June 13, 2026 at 10:27 pm

    This should be used for the second one:

    $("a.highlight").live('click', function(){
    
      alert($(this).text());
    
    });
    

    Please check this jsFiddle.

    However, if you are using jQuery 1.7 or later, you are encouraged to use on() method. Please check the doc for details

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a fake file input using an anchor tag and placed a
I have a grid and there is a column which contains <a> anchor tag
I am dynamically generating an anchor tag using jQuery. I have added an onclick
I have an anchor tag that has a jQuery click event linked to it.
I have created some JQuery that will expand a div 'popup' on hover and
I have created a function that shows/hides different messages according to a combination of
I have a while loop which creates a list of anchor tags each with
I have a highlighter function that formats the matched words to an anchor with
I'm working with jquery. I have an anchor tag that is generated dynamically in
I'm new to SO and a jQuery newbie. I have links being dynamically created

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.