Jeff Demos Jeff Demos - 5 months ago 13
Javascript Question

Jquery Target a tag in the third child of previous sibling

I'm not so great with traversing in jquery. Here is my markup:

<div class="row planarea">

<div class="col-md-6">
<h1>Agera Fixed Advantage 12</h1>
Fixed Price - 12 Months<br>
Utility: Con Edison

<div class="col-md-3">
<span class="price">$0.0799</span> <span class="killowats">/ kWh</span>

<div class="col-md-3">
<a class="nolink showmore" data-toggle="collapse" data-target="#24moscollapse" aria-expanded="false" aria-controls="24moscollapse">
<div class="selectdetails">
Details <i class="fa fa-chevron-circle-down" aria-hidden="true"></i>

<label >
<input type='radio' name="prefs" class="hidecheck" value="mail">



<div class="row collapse detailsrow" id="24moscollapse">
<div class="col-xs-12 plandetailsbox">

what I want to do is something similar to this:

$('.detailsrow').on('', function () {
$(this).prev().closest().("a.showmore").html('<div class="selectdetails">Details <i class="fa fa-chevron-circle-up" aria- hidden="true"></i></div>');

I can't seem to figure out how to target that a tag and it's getting kind of confusing. I need to target what I believe is the a tag in the third child of the previous sibling for every repeated row of this information. Any help would be appreciated.


closest() finds the first parent. And closest(selector) finds the first selector matched parent.

Whereas, you are looking for a child. So, you can use find(selector).

Change this:


To this: