Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
40
rated 0 times [  41] [ 1]  / answers: 1 / hits: 15854  / 11 Years ago, fri, january 25, 2013, 12:00:00

Possible Duplicate:

Highlight text range using JavaScript

Find text string in jQuery and make it bold






Supposing I have a bunch of file paths, similar to:




  • /Volumes/A//Array/05_SCRIPTS/staging/tree/04_OUTPUTS/MPEG_FF_PS_wCropping/01_NBC_Youtube/Backlog/Archive/LawAndOrder_S20


  • /Volumes/A//AArray/05_SCRIPTS/staging/tree/04_OUTPUTS/MPEG_FF_PS_wCropping/01_NBC_Youtube/Backlog/Archive/LawAndOrder_S20/nbcnetwork-pds-E8818-US-insert-20121020




How would I highlight all matches of specific text on the page. For example, if 04 was what I was looking for, it would do something like:



$(source).find('04').addClass('highlight');


This is pseudocode that is probably way off the mark, but this is what I'm looking to do.


More From » javascript

 Answers
138

http://jsfiddle.net/Aku4y/



var t = $(source).html();
t = t.replace(/04/g, <span class='highlight'>04</span>);
$(source).html(t);

[#80636] Wednesday, January 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxinec

Total Points: 117
Total Questions: 116
Total Answers: 116

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
maxinec questions
;