I want this text inside The solution change based on the current browser, with older version of jQuery I use Demo: http://jsfiddle.net/IrvinDominin/bKPcX/ So if I assume correctly, you want the text inside a particular div to be highlighted.. Working jsFiddle Source
$.browser
, but now is deleted; to check it's IE and use the correct code check if document.body.createTextRange
exist like:$(document).ready(function () {
selectText('sample_div');
});
function selectText(element) {
var text = document.getElementById(element);
if (document.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}
function selectText(element) {
var doc = document
, text = doc.getElementById(element)
, range, selection
;
if (doc.body.createTextRange) { //ms
range = doc.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) { //all others
selection = window.getSelection();
range = doc.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}