The reason you’re seeing this behavior is that this within the each call is a String object instance, not a string primitive. JavaScript has both. In a switch statement, the comparison with the cases is via ===, and a string instance is not === to a string primitive.
Three ways to fix it:
-
If you change your switch to:
switch (String(this)) {…that will turn it back into a primitive, whereupon your
switchworks. -
As VisioN points out in the comments below, use the arguments that
$.eachpasses (each string — as a primitive — will be provided as the second argument):$.each(typ, function(index, value) { switch (value) { // ... } }); -
Use any of the alternatives discussed in this other answer (one of which is a nice simple
forloop).
Side note: You’re falling prey to The Horror of Implicit Globals by not declaring your typ variable.