I use this code http://www.openjs.com/scripts/events/keyboard_shortcuts/index.php for handling keyboard shortcuts.
shortcut.add("Ctrl+Z",function() {
setTimeout(function() {
var val= $("textarea").val();
var length = val.split("\n").length;
alert(length);
}, 100);
},{
'type':'keydown',
'propagate':true,
'target':document.getElementById("textarea")
});
I have problem when ctrl+z is pressed and there is nothing to undo – the alerts 2 ,not 1.
I’m not sure what the structure of your page is (a link would be handy), but I do notice a potential issue. In one place you’re requesting for an element with id “textarea”:
But in another place you’re querying for all elements of type textarea, of which there could be multiple:
Did you intend to access an element with id “textarea” like this:
That could be related to your issue if there are multiple textarea elements on your page.