Search all words in the input field, then replace all matching words in the div tag

By | July 17, 2018
$('#srctxt div').each(function() {
    var dari = $('#box').val();
    var text = $(this).text();
    $(this).html(text.replace(dari, '<b>'+dari+'</b>')); 
<script src=""></script>

<form method="POST">

<input type="text" id="box" value="love"> // working
<input type="text" id="box" value="love girl"> // not working

<div id="srctxt">
<div>i love you</div>
<div>love girl</div>
<div>not love</div>
<div>love love love</div>

Leave a Reply

Your email address will not be published. Required fields are marked *