I have multiple accordion in single page and i am seraching the keword in the header of each accordion and want to highlight the search text but the following code is searching the keyword but not highlighting the text.
enter code here
var search = document.getElementById('searchAns'),
accordions = document.querySelectorAll('.find-ans-card');
if (search) {
// Apply search
search.addEventListener('input', function () {
var searchText = search.value.toLowerCase();
Array.prototype.forEach.call(accordions, function (accordion) {
if (accordion.innerText.toLowerCase().indexOf(searchText) >= 0) {
accordion.style.display = 'block';
//accordion.innerText.toLowerCase().indexOf(searchText).style.bgColor = 'black';
}
else {
accordion.style.display = 'none';
}
});
});
}