I am working on a website where I would like to be able to display a box containing syntax-highlighted source code for the user to copy. When I click on the box, giving it f
You can use the document.createRange();
method to select the text from a particular element.
and to handle the ctrl+a you can use the jQuery keydown
method and can call the JS code to select the DIV text.
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
please see jsfiddle
here jsfiddle.