I have an input textbox for users to search for another user by either first name, Last Name or full name and if name found, either hide the non-match one or color the found one.
My structure looks
const userSerach = ($("#userId").val() || '').toLowerCase();
const usersInRow = $(this).find('td').eq(6);
const users = usersInRow[0].innerText;
const userFound = users.substring(users.contains(userSerach)).toLowerCase();
if (userFound.length > 0) {
$(userFound).css('color', 'red');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="form-control" id="userId" placeholder="Search by user's name" value="">
<dl>
<dt>ADMINISTRATORs (<span style="color: red;">3</span>)</dt>
<dd>Louis,Edward</dd>
<dd>Gary,Anthony</dd>
<dd>Carlson,Matthew</dd>
</dl>
2
Answers
What I understood looking at your code is that you want to search matching text into
<dd>
and want to highlight them.You can do it like below:
I used pure js and css, this may help you