Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to highlight (temporarily) words in html. I can successfully edit the text content so that the
<mark>
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
Comments
[no name] 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 24-Sep-12 15:13pm    
am showing the code now...can you help?

1 solution

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


      $('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;
                  aindx[aindx.length]=a.indexOf(result)+aindx[prev];
                  $(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

              a=b;
          }


                  });



          } catch (ex) { e.preventDefault(); }
      });
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900