[jQuery] Selecting text of an object (in this case a span) onclick.
Nothing gets selected. The correct text is logged to the console in
FireBug. I don't think this is a jquery problem, but not sure how to
figure this out. Thanks in advance for any help. Code below:
<html>
<head>
<title>Testing Text Selection</title>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/
files/jquery-1.2.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
$('div.pageInfo span').click(
function() {
if(document.createRange) {
rangeToSelect = document.createRange();
rangeToSelect.selectNode(this.firstChild);
console.log(this.firstChild);
return false;
}
}
);
}
);
</script>
</head>
<body>
<div class="pageInfo">
Some text which I don't care much about.
<span>I want this text to be selected when it's clicked for easy
copying.</span>
</div>
</body>
</html>