views:

17

answers:

1

I need to find a way to the get the class from a li and then add that class to a div that wraps all my main content. so...

<div class="structBody">
<ul id="ContentBreadCrumbsColor">
<li class="teal"></li>
</ul>

  <div class="cntrWrap LI_CLASS_GOES_HERE">
    HTML TEXT GOES HERE
  </div>

</div>

Can anyone help? I have tried so many different ideas but I'm still very new to jQuery.

+1  A: 

This should do it.

$(document).ready(function()
        {
            $('div.structBody').addClass($('li.teal').attr('class'));
        }
);

I'd recommend the official jQuery website's documentation, if you haven't already gone through it.

jwiscarson
Thank you that did work but the only problem is if the li has a class of blue it still adds teal. I need it to add whatever class the li has. The li class is different on every page.
Ashlee
Do you have more than one li on each page? If not, you can remove `.teal` from the above code.
jwiscarson
Yes that worked I changed it to this: <code>$(document).ready(function() { $('div.structBody').addClass($('ul#ContentBreadCrumbsColor li').attr('class')); } ); </code>
Ashlee
Glad to help. When you're satisfied, just click the checkbox next to my response to accept this as the answer.
jwiscarson