Question

When an active class is present on the <a>, I would like to move that class up to it's highest parent; the <div class="views-row">

<div class="views-row-unformatted views-row views-row-2 views-row-even">
  <div class="title">
    <span class="field-content">
      <a class="active">
        <h3>Title Text</h3>
      </a>
    </span>    
  </div>
</div>

I am limited to working in the theme layer and have only jQuery and CSS as my tools.

Was it helpful?

Solution

You can use :has selector or has method:

$('div.views-row:has(a.active)') 
                   .addClass('active') 
                   .find('a.active') 
                   .removeClass('active'); 

http://jsfiddle.net/RmxWq/

OTHER TIPS

use :has() , parents() and addClass().

$('a:has(".active")').parents('div.views-row').addClass('active');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top