var item = $(".an-search-list-bloc");
var stringFilter = "i PHI oi 100";
var highlight = function($element, pattern) {
if (typeof pattern === 'string' && !pattern.length) return;
var regex = (typeof pattern === 'string') ? new RegExp(pattern, 'i') : pattern;
var highlight = function(node) {
var skip = 0;
if (node.nodeType === 3) {
var pos = node.data.search(regex);
if (pos >= 0 && node.data.length > 0) {
if (node.parentNode && node.parentNode.classList.contains('highlight')) {
return skip;
}
var match = node.data.match(regex);
var spannode = document.createElement('span');
spannode.className = 'highlight';
var middlebit = node.splitText(pos);
var endbit = middlebit.splitText(match[0].length);
var middleclone = middlebit.cloneNode(true);
spannode.appendChild(middleclone);
middlebit.parentNode.replaceChild(spannode, middlebit);
skip = 1;
}
} else if (node.nodeType === 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
for (var i = 0; i < node.childNodes.length; ++i) {
i += highlight(node.childNodes[i]);
}
}
return skip;
};
return $element.each(function() {
highlight(this);
});
};
let stringFilterArray = stringFilter.split(' ');
stringFilterArray.sort(function(a, b) {
return b.length - a.length || // sort by length, if equal then
b.localeCompare(a); // sort by dictionary order
});
console.log(item);
let stringFilterRegexFormatted = stringFilterArray.join('|');
highlight(item, stringFilterRegexFormatted);
var stringFilter2 = "N°7 0";
let stringFilterArray2 = stringFilter2.split(' ');
stringFilterArray2.sort(function(a, b) {
return b.length - a.length || // sort by length, if equal then
b.localeCompare(a); // sort by dictionary order
});
let stringFilterRegexFormatted2 = stringFilterArray2.join('|');
setTimeout(function(){ highlight(item,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.