HYUTS HYUTS - 1 year ago 65
jQuery Question

How can I add a class using jQuery in this loop

I would like to add a class to each of my cardCount elements using jQuery.

if (i == 13 || i == 26 || i == 39) {
for (ii=0; ii<13; ii++){
cardCount += "<span>" + cardOrder[ii] + "</span>"}

Thank you.


for (ii=0; ii<13; ii++){
cardCreate += "<span class=" + changeClass + '>' + cardOrder[ii] + "</span>";

Answer Source

If you want to use jquery after all you may try this:


Note that the code above will apply the class "myClass" to all of your spans.

But, do this is better:

cardCount += "<span class='myClass'>" + cardOrder[ii] + "</span>"}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download