Skip to main content
added 28 characters in body
Source Link
Mohammed Joraid
  • 6.6k
  • 2
  • 29
  • 38

Capture the search phrase (the word you are searching or looking for). Capture the search area (the table or paragraph you are searching into). Look into the search area to see if you can find the search phrase. Once it exists, replace with a string that has an HTML element tag surrounding it.

Replace the searched word with the same word but wrapped in a span that has certain CSS class. Use CSS to customize the look.

 var toLookInto = $("#toLookInto").html(); $("#toFind").on("keyup", function() { var toFind = $("#toFind").val(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight">' + toFind + '</span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <button<lable>The id="buttonclick">text Findfield <will be triggered on every key pressed</button>label>

Capture the search phrase (the word you are searching or looking for). Capture the search area (the table or paragraph you are searching into). Look into the search area to see if you can find the search phrase. Once it exists, replace with a string that has an HTML element tag surrounding it.

Replace the searched word with the same word but wrapped in a span that has certain CSS class. Use CSS to customize the look.

 var toLookInto = $("#toLookInto").html(); $("#toFind").on("keyup", function() { var toFind = $("#toFind").val(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight">' + toFind + '</span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <button id="buttonclick"> Find </button>

Capture the search phrase (the word you are searching or looking for). Capture the search area (the table or paragraph you are searching into). Look into the search area to see if you can find the search phrase. Once it exists, replace with a string that has an HTML element tag surrounding it.

Replace the searched word with the same word but wrapped in a span that has certain CSS class. Use CSS to customize the look.

 var toLookInto = $("#toLookInto").html(); $("#toFind").on("keyup", function() { var toFind = $("#toFind").val(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight">' + toFind + '</span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <lable>The text field will be triggered on every key pressed</label>

added 50 characters in body
Source Link
Mohammed Joraid
  • 6.6k
  • 2
  • 29
  • 38

Capture the search phrase (the word you are searching or looking for). Capture Capture the search area (the table or paragraph you are searching into). Look into the search area to see if you can find the search phrase. Once it exists, replace with a string that has an HTML element tag surrounding it.

Replace the searched word, with the same word, place but wrapped in a span that has certain CSS class. Use CSS to customize the look.

 var toLookInto = $("#toLookInto").html(); $("#toFind").on("keyup", function() { var toFind = $("#toFind").val(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight">' + toFind + '</span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <button id="buttonclick"> Find </button>

Capture the search phrase. Capture the search area.

Replace the searched word, with the same word, place wrapped in a span that has certain CSS class. Use CSS to customize the look.

 var toLookInto = $("#toLookInto").html(); $("#toFind").on("keyup", function() { var toFind = $("#toFind").val(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight">' + toFind + '</span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <button id="buttonclick"> Find </button>

Capture the search phrase (the word you are searching or looking for). Capture the search area (the table or paragraph you are searching into). Look into the search area to see if you can find the search phrase. Once it exists, replace with a string that has an HTML element tag surrounding it.

Replace the searched word with the same word but wrapped in a span that has certain CSS class. Use CSS to customize the look.

 var toLookInto = $("#toLookInto").html(); $("#toFind").on("keyup", function() { var toFind = $("#toFind").val(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight">' + toFind + '</span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <button id="buttonclick"> Find </button>

added 50 characters in body
Source Link
Mohammed Joraid
  • 6.6k
  • 2
  • 29
  • 38

Capture the search phrase. Capture the search area.

Replace the searched word, with the same word, place wrapped in a span that has certain CSS class. Use CSS to customize the look.

$("#buttonclick").on("click", function() { var toLookInto = $(".in""#toLookInto").unwraphtml();  var toFind =   $("#toFind").valon("keyup", function(); { var toLookIntotoFind = $("#toLookInto""#toFind").htmlval(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight"><span class="in">'class="highlight">' + toFind + '</span></span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <button id="buttonclick"> Find </button>

Capture the search phrase. Capture the search area.

Replace the searched word, with the same word, place wrapped in a span that has certain CSS class. Use CSS to customize the look.

$("#buttonclick").on("click", function() {  $(".in").unwrap();  var toFind = $("#toFind").val(); var toLookInto = $("#toLookInto").html(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight"><span class="in">' + toFind + '</span></span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <button id="buttonclick"> Find </button>

Capture the search phrase. Capture the search area.

Replace the searched word, with the same word, place wrapped in a span that has certain CSS class. Use CSS to customize the look.

 var toLookInto = $("#toLookInto").html();   $("#toFind").on("keyup", function() { var toFind = $("#toFind").val(); var regx = new RegExp(toFind, "g"); var newstring = toLookInto.replace(regx, '<span class="highlight">' + toFind + '</span>') $("#toLookInto").html(newstring) });
.highlight { color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <p id="toLookInto"> dummy text foo bar cat mewo dummy text foo bar cat mewo dummy text foo something odd bar cat mewo dummy text foo bar cat mewo </p> <br> <input type "text" id="toFind" /> <button id="buttonclick"> Find </button>

added 50 characters in body
Source Link
Mohammed Joraid
  • 6.6k
  • 2
  • 29
  • 38
Loading
Source Link
Mohammed Joraid
  • 6.6k
  • 2
  • 29
  • 38
Loading