When person clicks on any <code>
element it'll auto highlight everything inside plus copy to clipboard. I'm writing articles and there are lots of copy / paste commands being used for SSH. It would be nice if I could shave off a few dozen clicks for the visitor. I get this error when I try the code below:
$(function () {
$(document).on('click', 'code', function () {
this.select();
});
});
I write these articles in markdown, and when I export, it's just clean code. I would prefer if I didn't have to use Flash or add a class or id to the html. Instead, just assume everything inside <code>
should be copied to clipboard on click.
I also just tried this, but still no luck.
<script type="text/javascript">
$('code').focus(function () {
this.select();
this.setSelectionRange(0, 9999);
}).mouseup(function (e) {
e.preventDefault();
});
</script>
source