これを試して
function SelectText(element) {
var doc = document;
var text = doc.getElementById(element);
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}
$(function() {
$('.select').click(function() {
SelectText('selectme');
});
});
https://stackoverflow.com/a/987376/1330581から取得
例http://jsfiddle.net/edelman/KcX6A/339/
アップデート:
クリックした同じ要素のコンテンツを選択するには:
function SelectText(element) {
var doc = document;
var text = element;
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}
$(function() {
$('.select').click(function() {
SelectText($(this)[0]); //Brackets are more efficiently that .get(0) method
});
});
例: http://jsfiddle.net/qBaWf/