matching an element's class to another element's ID, or *part* of another element's ID

matching an element's class to another element's ID, or *part* of another element's ID

hello again

Such a simple concept but I'm struggling to express it ... apologies in advance for my verbosity.

I have a container div with a class, e.g., <div id="container" class="apples">; I want to use that class to do two things:

1. add a class (e.g., 'active') to the nav element whose ID matches the class of div#container (e.g., #nav-primary li# apples)
2. add the same class to another element if *part* of this element's ID matches the class of #container (e.g., div#secondary-apples)

I assume there's an .each() loop to check the primary nav's list items' IDs, and to check the div IDs of the secondary nav ... though the latter needs to have its prefix trimmed ... or should I say more simply if the secondary nav div IDs *contain* the class of div#container?

I've tried a few variations of something like this:

<script type="text/javascript">
   $(document).ready(function() {

       $('#nav-primary li').each(function(){
          var containerClass = $('#container').attr('class');
          var secondaryID = $('#nav-primary li').attr('id');
           
            // something like
            if ('#nav-primary li id' == (containerClass)
            {
            }

            // or should I first store a variable of the LI's ID and do something like this:
            if ( secondaryID == containerClass )
            {
            }

            //   and for the trickier part, how do I filter/trim the secondary nav div IDs, something like this:
          var secondaryNavID = $('#aux-left div[id ... something here to strip the 'secondary-' bit ... ]');

      });    // end each

});    // end doc.ready.func
</script>



The markup is, e.g.:

<div id="container" class="apples"> ...
   <ul id="nav-primary">
      <li id="apples"> ...
      <li id="oranges"> ...
      <li id="bananas"> ...
   </ul>



<div id="aux-left">
   <div id="secondary-apples"> ...
   <div id="secondary-oranges"> ...
   <div id="secondary-bananas"> ...



Many thanks in advance for any suggestions,
svs