I have a div and there is a text in it.I want a part of that text to be selected programmatically according position value of characters.
Code without any error checking ahead. Use at your own risk!
function highlight(pattern) {
var text = $("#textdiv").text();
var around = text.split(pattern);
$("#textdiv").html(around[0] + "" + pattern + "" + around[1]);
}
$(document).ready(function() {
highlight("world");
})
.highlight {
background-color: yellow;
}
Hello world. I'm Hugo!