Search code examples
javascriptjqueryswitch-statementcase-sensitive

Case-insensitive switch-case


OK, so let's say I have this:

$(function() {
  $('#good_evening').keyup(function () {
    switch($(this).val()) {
    case 'Test':
      // DO STUFF HERE
      break;
    }
  });
});

... this would only run if you typed "Test" and not "test" or "TEST". How do I make it case-insensitive for JavaScript functions?


Solution

  • switch($(this).val().toLowerCase()) {
        case 'test':
        // DO STUFF HERE          
        break;
    }