i thought if & switch statements compared things same way in different formats. however, when trying capture backspace keycode switch 1 picked on comparison. why this?
https://jsfiddle.net/ogbw8g8u/3/
$(window).on('keydown', function (e) { e.preventdefault(); if( e.keycode == 8 ) { $('div').append('<p>if</p>'); } switch (e.keycode) { case 8: // backspace $('div').append('<p>switch</p>'); break; } });
the error have not statement, capitalization. if statement should not have k
in keycode
capitalized. should be:
if (e.keycode == 8) { ... }
Comments
Post a Comment