I am using a regex replace to <mark></mark>
input text. The problem I am running into is that it takes all text from a holder div and replaces it into a variable and adds the mark tags. Then places it back into the div holder. When I do this, if I type in "<p>"
, it highlights the actual <p>
and outputs it back into the div.
Is there anyway to get around this? Here is my marking code:
function Search() {
var Notes = document.getElementById("NoteHolder").innerHTML;
var i = document.getElementById("Bar").value;
var inputReOne = $.trim(i);
var inp = inputReOne.replace(".", "\.").replace("<", "").replace(">", "").replace(
"/", "").replace(/\\/, "");
document.getElementById("Bar").value = inp;
if ($.trim(inp) !== '') {
var InpComp = inp.toUpperCase();
var Ind = tags.indexOf(InpComp);
if (Ind === -1) {
var inpReg = new RegExp(inp, "im");
var WordCheck = Notes.match(inpReg);
if (WordCheck !== null) {
tags.push(InpComp);
var SearchReq = new RegExp("(" + inp + ")", "gim");
var after = Notes.replace(SearchReq, "<mark class=" +
ColorOptionReady + ">$1</mark>");
document.getElementById("NoteHolder").innerHTML = after;
}
HTML:
<body>
<div>
<p id="form">
<input class="SearchInp" autocomplete="off" id="Bar" name="Input" type="text" placeholder="Search for word or phrase">
<input class="SearchInp" type="submit" id="sea" onClick="Search ()" value="Search"> <div id="NoteHolder">
</p>
<p class="NoteOp" id="NoteOne">This is a test paragraph uses to TeSt filters.</p>
<p class="NoteOp" id="NoteTwo">Random words, I need to see if it will mess up mark</p>
</div>
<script src="Test.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"> </script>
</body>
` tags back?
– Hawkeye Mar 11 '16 at 22:21