View Single Post
  #3 (permalink)  
Old Mar 15th, 2008, 17:00
mikemike2004 mikemike2004 is offline
New Member
Join Date: Mar 2008
Location: United Kingdom
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Highlighting text selections

I have tried innerHTML and it works the same as the first method. For the first method I initially parse the whole text node that's handling the selection into three parts, the substring BEFORE the selected string, the substring AFTER the selected substring and the selected subtring. Then I created a text node contianing the BEFORE substring, a text node containing the AFTER substring and a text node containing the "<span>" + the selected substring.
Then I removed the entire text node containing the selected substring and append the newly created text nodes back on. It worked but not in a very stable way. Also, no other highlighting could be done on texts appearing after the highlighted string! I did the same using innerHTML and the result is the same.
Reply With Quote