Orkun
Orkun

Reputation: 7228

Jquery: find '.myclass' which has a parent div with class '.active'

As I am typing this question, SO is making suggestions but I couldnT find anything that is quite like my problem.. If it s a dupe of smth, sorry in advance.

Basically,

 <li role="presentation" class="active"><a class="graph-switch" href="#basari" data-metric="accuracy">BASARI</a></li>
 <li role="presentation"><a href="#doygunluk" class="graph-switch" data-metric="readiness">DOYGUNLUK</a></li>
 <li role="presentation"><a href="#deneyim" class="graph-switch" data-metric="experience">DENEYIM</a></li>

I have these li s. The first one is the active one, I want to get the data-metric="accuracy"

I m trying things like:

var metric = $(".graph-switch").parents('.active').first().data('metric');

but it s wrong and i know it s ugly.. There has to be a better way.. Any ideas?

Upvotes: 0

Views: 28

Answers (1)

j08691
j08691

Reputation: 207861

You should be able to use:

$('li.active a.graph-switch').data('metric')

Upvotes: 1

Related Questions