I want to select content text in certain tags like code
by clicking on it (ready for copy-paste).
I foudn solutions when you have an ID, but my code tags don't have IDs:
<p>When I click <code>this code</code> I want it to be selected.</p>
<p>The code tags don't have IDs or tag names.</p>
<p>Here's some <code>other code</code>.</p>
This doesn't work:
$("code").click(function(){
$(this).select();
});
It seems select()
is only for inputs and textareas.