I’m using append in the following way:
$('#city').append('<div class="c">' + value['name'] + '. ' + value['city'] + ', ' +
value['state'] +' ' + value['zip'] + ' ' + '</div>');
Which results in something like this:
<div class="c">
Antone Stark. Doyletown, Rhode Island 43467
</div>
How do you use value[‘state’] to name the class?
<div class="MyCustomClass">
If the states were two letter codes, you could do this:
However, classes are space-separated meaning they are treated as separate when split up by spaces. So if you add something there with a space (like “Rhode Island”), it will treat them as separate classes (e.g., “Rhode” and “Island”) so you may wish to replace spaces with an underscore or the like.
So in the case of Rhode Island, that will produce:
which you can then reference in CSS:
or jQuery:
etc.
However, if you are not repeating these, it might be more appropriate to generate it as an id rather than a class (i.e., to produce
<div id="Rhode_Island">instead of<div class="Rhode_Island">).