Click here to Skip to main content
11,718,589 members (84,691 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Javascript HTML DOM
I am trying to highlight (temporarily) words in html. I can successfully edit the text content so that the
tags are in the correct place in the text string, and it appears I am saving the edited string correctly, BUT....

the text displayed in the browser does not change!
Posted 22-Sep-12 16:16pm
Wes Aday at 22-Sep-12 22:47pm
And how do you expect us to know how you screwed things up when you do not show us what you have done?
Member 9444740 at 24-Sep-12 15:13pm
am showing the code now...can you help?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

here is the code:
$(document).ready(function (e) {
      $('#submit').click(function (e) {
          try {
              var $inputTxt = $('#search');
              result = $inputTxt.val();

      $('p').each(function () {
          var a=$(this).html().toString();
          var aindx=[];
          while(a.indexOf(result) >= 0){
              //alert("string found "+a.indexOf(result)+" position");

              var b=a.substring((a.indexOf(result)+result.length));
              if(aindx.length > 0) {
                  var prev=aindx.length-1;
                  $(this).html(a.substring(0,(aindx[aindx.length]-1))+'<mark id="tmprry">'+result+'</mark>'+a.substring(aindx[aindx.length+result.length-1]));
              } else {
                  aindx[0] =a.indexOf(result);
                  $(this).html(a.substring(0,(aindx[0]-1))+'<mark id="tmprry">'+result+'</mark>'+a.substring(aindx[0]));
              //insert mark around position



          } catch (ex) { e.preventDefault(); }

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 651
1 OriginalGriff 210
2 F-ES Sitecore 185
3 Jochen Arndt 160
4 Maciej Los 130
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415

Advertise | Privacy | Mobile
Web02 | 2.8.150901.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100