troubleshooting Question

modify change color of text

Avatar of Mark Branscum
Mark BranscumFlag for United States of America asked on
9 Comments2 Solutions152 ViewsLast Modified:
Curious from those in the know .... can the below be modified to the same thing but without REGEX    :) but still with Jquery
div contains text like this
The basic idea is I just wanna find a specific string and change that strings color and not the rest

David Lion Killer
Marshal Dillan
David Caradine
Penny March

var search = 'bar';
$(document).ready(function () {
    $("div:contains('"+search+"')").each(function () {
        var regex = new RegExp(search,'gi');
        $(this).html($(this).text().replace(regex, "<span class='red'>"+search+"</span>"));
Join our community to see this answer!
Unlock 2 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros