This is best used in JavaScript / jQuery. Here is an example implementation
var originalText = $("#user-text").text(); $("textarea").on("keyup", function() { var enteredText = $("textarea").val(); var length = enteredText.length; if (originalText.search(enteredText) == 0) { $("#user-text").html("<span class='highlight'>" + originalText.slice(0, length) + "</span>" + originalText.slice(length, originalText.length)); } });
.highlight { background: gold; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <textarea></textarea> <p id="user-text">This is a paragraph</p>
You want to save the paragraph value in a variable outside the function.
Then you want to listen to the keyup function and get user input. Find if this is happening in the source line, and then change the html of the source line.
We will insert a class to highlight the input, if there is an exact match. Then we add the rest of the line without styling.
source share