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>")); });});
Hey guys just got in from work ... I have wanted to get here to look this over all day ..... sorry for the delay ....... Julian first I want to say ... I apologize I simply did not recall that we basically already put this together .... I feel bad about that ..... I went back over and looked at it .... and there it was ..........
That being said .... I am going to check these out ....I already know from the previous code you did that its going to work ..... but will give it a go .... also thank you for the explaining the code as you did .... I can not tell you how much that means to me ..... I learn so much from your post ....
Julian most likely its me ........ but Ive tried both .... it is coloring the name searched for but it is giving me this order now ... did I mess it up
David Lion KillerMarshal
DillanDavid CaradinePenny
March
David Caradine is not bold as I show it here its red as we are aiming for but the order is as you see it now too instead of
David Lion Killer
Marshal Dillan
David Caradine
Penny March
Mark Branscum
ASKER
I found the problem and fixed it changed $(this).text to .html ... it is working .......
In this case I felt these were the best solutions so the points go to Julian .....
Thank you Julian, seriously I learn every time you post ..... as for regex I guess it is in my future .... right now its HTML, CSS, JQUERY, javascript ... my plate is full but I am working on it :) thanx again
https://jsfiddle.net/6fn06593/
Open in new window
Open in new window
Open in new window