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(){
});
Because the first link immediately precedes the second, you can use
prevto get to the link andattrto get the value of theclassattribute:That will give you “third link1”, because that’s the value of the
classattribute. If you only want the first part, you could split it:Here’s a working example.