Click here to Skip to main content
15,913,221 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to highlight some portion of text in a textbox. Hence tried using a freetextbox, but I cannot select a portion of text as it can be done in richtextbox in windows forms.Can anyone share code how to do so.Any help will be appreciated.
Posted

1 solution

Try using below method, pass highlight text as search text..
$("[id$='_tbSearch']").highlight('HIGHLIGHT TEXT', "highlight");

jQuery.fn.highlight = function (str, className) {
    var regex = new RegExp(str, "gi");
    return this.each(function () {
        this.innerHTML = this.innerHTML.replace(regex, function (matched) {
            return "<span style="background-color:yellow;border:0px solid gray;">" + matched + "</span>";
        });
    });
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900