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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:46:47+00:00 2026-05-26T09:46:47+00:00

i have 5 divs , in each divs there’s two links as shown in

  • 0

i have 5 divs , in each divs there’s two links as shown in the example below

    <div id="wrapper">
<a href="2332" class="first link1">Link1</a><a href="link2" class="link2">Link2</a>
   </div>

    <div id="wrapper">
<a href="1221" class="second link1">Link1</a><a href="link2" class="link2">Link2</a>
   </div>

    <div id="wrapper">
<a href="789" class="third link1">Link1</a><a href="link2" class="link2">Link2</a>
   </div>

    <div id="wrapper">
<a href="345" class="abc link1">Link1</a><a href="link2" class="link2">Link2</a>
   </div>

    <div id="wrapper">
<a href="123" class="bcd link1">Link1</a><a href="link2" class="link2">Link2</a>
   </div>

How can i use javascript/jquery to GET the CLASS of link1(inside the same div not others) when LINK2 is clicked.
Okay when i clicked the third div’s link2 link , it will give me “third” (excluding the link1 which is also a class).

the click function is:

$('.link2').click(function(){

});
  • 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-05-26T09:46:47+00:00Added an answer on May 26, 2026 at 9:46 am

    Because the first link immediately precedes the second, you can use prev to get to the link and attr to get the value of the class attribute:

    $('.link2').click(function(){
        var prevClass = $(this).prev().attr("class");
    });
    

    That will give you “third link1”, because that’s the value of the class attribute. If you only want the first part, you could split it:

    var prevClass = $(this).prev().attr("class").split(" ")[0];
    

    Here’s a working example.

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

Sidebar

Related Questions

I have 8 divs. Each div has the class 'pre-loader'. In addition to thas
Currently, I have 2 divs, each with a CSS class. They are directly below
I have a wrapper div containing 10 thumbnail divs each of which contains 10
I have two divs, <div class=number></div> and <div class=label></div> . I would like to
I have 2 divs above each others, at a given moment one is shown
So I have 2 divs, each with n-elements. There are n-pairs of elements across
i have two divs on a page. each has several dijits. i have atoggle
I have 10 divs on my page and each div will render its own
I have two divs floated left so that they appear next to each other.
I have several divs with one class on a page. <div class=main/> <div class=main/>

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.