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

By | July 17, 2018
Questions:
$('#srctxt div').each(function() {
    var dari = $('#box').val();
    var text = $(this).text();
    $(this).html(text.replace(dari, '<b>'+dari+'</b>')); 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></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>
</div>
</form>
Answers:

Leave a Reply

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