I'm doing a filter in jquery but I'm wrong in my logic somewhere and I can not seem to get out of the way. My filter is not fading with some words that I type, it brings me the whole block, even the typed word not being in the item. I'm having trouble solving it.
This is the portal: link
This is my script (just play on the page console to test)
$("input[name='_3_keywords']").keyup(function() {
var palavrasChave = $("input[name='_3_keywords']").val();
if (palavrasChave.trim() !== "") {
var content = document.querySelectorAll('.asset-full-content.show-asset-title');
content.forEach((element) => {
element.style.display = 'none';
});
$(".taglib-header").hide();
var $elements = $(".taglib-header:contains(" + palavrasChave + ")");
$elements.each((index) => {
$elements[index].nextElementSibling.style.display = 'block';
});
$elements.show();
var $elementsContent = $(".asset-full-content:contains(" + palavrasChave + ")");
$elementsContent.each((index) => {
$($elementsContent[index]).show();
console.log($($elementsContent[index]).prev());
$($elementsContent[index]).prev().show(); $elementContent.style.display = 'none';
});
} else {
var elements = $(".taglib-header");
elements.show();
elements.each((index) => {
elements[index].nextElementSibling.style.display = 'none';
});
}
});