3
I’m creating a search bar where the user type and filter in real time the content of <li>
. I have a similar code:
HTML
<ul id="list-search-filter-map">
<li><a href="">Conteudo 1</li>
<li><a href="">Conteudo 2</li>
<li><a href="">Conteudo 3</li>
</ul>
jQuery
<script language="javascript" type="text/javascript">
function filterMap(element) {
var value = $(element).val().toLowerCase();
$("#list-search-filter-map > li").each(function() {
if ($(this).text().toLowerCase().search(value) > -1) {
$(this).show();
}
else {
$(this).hide();
}
});
}
</script>
This is working as I need, but I want to put some content inside the tags <a>
and it can also filter through them. So my HTML would look something like this:
HTML
<ul id="list-search-filter-map">
<li><a href="" data-cidade="São Paulo" data-estado="SP">Conteudo 1</li>
<li><a href="" data-cidade="Rio de Janeiro" data-estado="RJ">Conteudo 2</li>
<li><a href="" data-cidade="Curitiba" data-estado="PR">Conteudo 3</li>
</ul>
That is, if the user also type Rio de Janeiro
will find the Content2
I think AP wants to Filtre by date and text within the link @Sergio
– BrTkCa
@Lucascosta the AP wrote "That is, if the user also type Rio de Janeiro will find the Content 2", hence this suggestion.
– Sergio
"and he can also filter through them". That way if he type Rio de Janeiro will find Content 2, but if Type Content 2 will not find anything
– BrTkCa
@Lucascosta ah, ok. Then that would be: https://jsfiddle.net/01ycfygj/ I will edit after knowing better what AP wants.
– Sergio