Reputation: 385
I have this glossary page design with a search filter. I just noticed the filter is filtering based on all the html and not just the title and p tags. For example if put an image that had a file name of hello.jpg and i searched hello. It would also filter that. So its reading all the html. I just want it to filter based on the H tag and P tags or just the specific tags/classes i set. Whatever is easier.
Any help would be much appreciated.
Here is my script so far
$("#txtSearch").on('keyup', function() {
var search = $(this).val().toLowerCase();
//Go through each list item and hide if not match search
$(".list-group-item").each(function() {
if ($(this).html().toLowerCase().indexOf(search) != -1) {
$(this).show();
}
else {
$(this).hide();
}
});
});
Upvotes: 0
Views: 44
Reputation: 5940
You can use the find
(.find("p,h1,h2,h3,h4,h5")
) function just before using .html()
.
Upvotes: 2