Reputation: 893
Ok so i have this
<div id="stadiumSeats1" class="fans eleven"></div>
<div id="stadium1" class="team activeteam eleven"><div>
Now what i want to do is find the first "activeteam" class and then target the previous div to that, in this scenario that would be stadiumSeats1
I tried using
$('.activeteam').prev('div');
$('.activeteam')[0].prev('div');
fwiw i am using hopscotch tour and my aim is to target that specific div.
I can access the stadium1 div fine with
$('.activeteam')[0];
But its the div before it i need. Theres lots of examples out there for $('#activeteam').prev('div');
But this is a bit different because im trying to access a particular element of a class so not sure how to structure it.
Upvotes: 0
Views: 58
Reputation: 777
$($('div').get($('div').index($('.activeteam'))-1))
https://jsfiddle.net/3g8afjhu/
Upvotes: 1