I have jQuery read some text then add a class based on the value of this text. (The text read is rendered by my CMS).
The HTML Looks like this:
<ul class="zoneSubscriptions">
<li>
<ul>
<li class="zoneName"><a href="#">Professional</a></li>
<li>Never</li>
</ul>
</li>
<li>
<ul>
<li class="zoneName"><a href="#">RTTM</a></li>
<li>Never</li>
</ul>
</li>
</ul>
I want to read the text of class="zoneName"
and add a class based on this.
JS to do this:
$(function() {
var zone = $( ".zoneName" ).text();
$( "#zones" ).addClass( zone );
});
This works without issue, however, I need it to add two classes, Professional
and RTTM
. What it adds is ProfessionalRTTM
.
My question is how would I add the classes while keeping a space between the words?
In other words it should render like this: class="Professional RTTM"
not class="ProfessionalRTTM"
Note: In my example there are two "zoneName"s. There could be anywhere from 1 to 5 or more when used live.