Search code examples
jquerydrupal-6jquery-1.3

How do I find an active class and move it to a parent container using jQuery?


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.


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/