What I'm trying to do is, when CTRL+A is pressed, the shortcut for select all; I don't want it select everything but only a specific area (like everything inside containers with a class of xyz). However, I'm not able to get anything working. Even just using select()
is not working. Example:
$("table").select();
I tried using a js solution I found here, but it was binding it if a certain area is active and I couldn't work around it. This is the code:
$(document).keydown(function(e) {
if (e.keyCode == 65 && e.ctrlKey) {
var range = document.createRange();
range.selectNode(document.getElementById('table'));
window.getSelection().addRange(range);
e.preventDefault();
}
});
I have created a jsfiddle here: http://jsfiddle.net/zpd8yLn7/
What I want is that the text inside class="class"
be selected whenever CTRL+A is pressed.