Click here to Skip to main content
13,002,169 members (75,294 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 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

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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170624.1 | Last Updated 22 Sep 2012
Copyright © CodeProject, 1999-2017
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