Jquery - Add a dynamic class to another DIV
<p>OK, perhaps the title doesnt best explain what im trying to achive but if I can explain better hopefully someone can help me out:</p>

<p>Im using the following code to select the text held within <code>&lt;a&gt;</code> and add it as the class of that element:</p>

<pre><code>$(".nav a").each(function () {
  var self = $(this);
  self.addClass(self.text());
});
</code></pre>

<p>So for instance:</p>

<pre><code>&lt;a class="nav" href="page1.html"&gt;Google&lt;/a&gt;
&lt;a class="nav" href="page2.html"&gt;Yahoo&lt;/a&gt;
&lt;a class="nav" href="page3.html"&gt;Bing&lt;/a&gt;
</code></pre>

<p>Becomes:</p>

<pre><code>&lt;a class="nav Google" href="page1.html"&gt;Google&lt;/a&gt;
&lt;a class="nav Yahoo" href="page2.html"&gt;Yahoo&lt;/a&gt;    
&lt;a class="nav Bing" href="page3.html"&gt;Bing&lt;/a&gt;
</code></pre>

<p>Im using another bit of code to find out which page the user is currently on, either Google, Yahoo or Bing, and I then allocate another class of 'Selected'</p>

<p>e.g If i was on the Google page the <code>&lt;a&gt;</code> class becomes:</p>

<pre><code>&lt;a class="nav Google selected" href="page1.html"&gt;Google&lt;/a&gt;
</code></pre>

<p>I would like to extend this a little further and can probably explain best via an example:</p>

<pre><code>&lt;a class="nav Google selected" href="page1.html"&gt;Google&lt;/a&gt;
&lt;a class="nav Yahoo" href="page2.html"&gt;Yahoo&lt;/a&gt;    
&lt;a class="nav Bing" href="page3.html"&gt;Bing&lt;/a&gt;

&lt;div class="container Google"&gt;

Lots of content

&lt;/div&gt;
</code></pre>

<p>So as above, when 'Google' has the class 'selected' add that to <code>&lt;div class="container"&gt;</code>, and the same for when the other links are clicked. </p>

<p>So in other words which ever <code>&lt;a&gt;</code> holds 'selected' add the previous class to <code>&lt;div class="container"&gt;</code></p>

<p>I know there are many ways to do this in far less 'hacky' ways but I have no other choice but to do it this way as I cannot edit the source of the page in anyway so it has to be a browser based solution rather than server side.</p>
