const getSearchHtml = (searchValue, item) => { let name = item.html || item.name; if (!searchValue) { return name; } let reg = new RegExp(escapeRegExp(searchValue), 'gi'); var elementToSearch = document.createElement('div'); elementToSearch.innerHTML = name.trim(); Array.from(elementToSearch.children).forEach(element => { let text = element.textContent; text = String(text).replace(reg, (str) => '<span class="search-highlight">' + str + '</span>'); element.innerHTML = text; }); return elementToSearch.innerHTML; };
166200cookie-checkSearch Highlight in HTML text/element