I’m using the jQuery below to change the font on a div element each time the onchange event fires for the select.
Trouble is, it does not work when I use the keyboard to cycle through the select list options.
It only fires when the select list is changed via mouseclick or letter click. How can I make it also respond to arrow up, down, right, left?
var changeHandler = function() {
$('.fontPreview').fadeOut();
var myFont = $('#myFonts :selected').val();
var myFont2 = $('#myFonts :selected').val().split(':')[0];
$('#fontPreviewSrc').attr('href','http://fonts.googleapis.com/css?family='+myFont);
$('.fontPreview').attr('style','font-family:'+myFont2+';font-style:normal;font-size:2em;padding-top:10px;white-space:nowrap');
$('.fontPreview').fadeIn(1500);
}
$("#myFonts").change(changeHandler).keypress(changeHandler);
I think you need something like this: