I'm creating a search bar where the user goes typing and is filtering the content of <li>
in real time. 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 it, but I want to put content inside the <a>
tags 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 typed Rio de Janeiro
will find Content 2