Note: Please note that this question is distinct from How to disable text selection highlighting using CSS?
Prior to asking, I reviewed the discussion history of the aforementioned question. Everything seems to be working well, except that I want to allow the CTRL+A
(Select All) function only within input elements.
The reason for this is because I am developing an HTML5 app for Desktop and I desire the same behavior as a GUI/Forms application.
Where should I start? Should I try binding the keypress
event to all elements and check for CTRL + A keyCode
? The drawback of this approach would involve managing everything and handling re-renders.
I would prefer a CSS solution, but I am open to any ideas.
Thank you in advance.
@EDIT: I came across this somewhat messy solution, but it is functional:
$(document).keydown(function(objEvent) {
if (objEvent.ctrlKey) {
if ((objEvent.keyCode === 65) || (objEvent.keyCode == 97)) {
if ($(objEvent.target).not("input").disableTextSelect().length) {
return false;
}
}
}
});