Click here to Skip to main content
15,883,940 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ok so i've got this half working:
I'm wanting to select all elements with a class of 'status-holder'. Then check what the innerHtml is of that element, then based on the value add a CSS class, existing code:

JavaScript
$('.status-holder').each(function () {
            switch ($(this).html().trim()) {
                case "Sent":
                    alert("fodo");
                    $(this).addClass('status-sent');
                case "Received":
                    $(this).addClass('status-received');
                case "In Progress":
                    $(this).addClass('status-inProgress');
                case "Completed":
                    $(this).addClass('status-completed');
            };
        });

problem is this doesn't just change the current iteration (what i want) it changes all the elements with class of 'status-holder'. i thought $(this) would be the current iteration, not refer to the selector.

Any help would be great.
Posted

1 solution

Are you missing
break;
statement after cases.
 
Share this answer
 
v2
Comments
Grant Weatherston 7-Jan-15 9:45am    
many thanks, sorry my brain isn't working today, forgot need break; in the switch statement. Some reason was thinking didnt need it in JS, my baad many thanks though
nagendrathecoder 7-Jan-15 9:48am    
You welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900