JSFiddle - React, Tailwind, and code Playground
by Michael Barros
HTML
Here is some text.
<p>
<div id="source" tabindex="1" >
<b><div></b>Hello world!<b></div></b>
</div>
<p>
Here is some more text.
CSS
#source {
border: 1px solid Black;
padding: 1em;
background-color: #f0f0f0;
}
JavaScript
function selectText1(containerid) {
if (document.selection) {
console.debug('document.selection');
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
console.debug('window.getSelection');
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
console.debug(range);
window.getSelection().addRange(range);
}
}
$(document).keydown(function(e) {
// console.log(`keyCode: ${e.keyCode} ctrlKey: ${e.ctrlKey}`);
if (e.keyCode == 65 && e.ctrlKey) {
selectText1('source');
e.preventDefault();
}
});