HYUTS HYUTS - 4 months ago 16
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.

UPDATED WORKING:

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

Answer

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

$("span").addClass("myClass");

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>"}