Monday, 19 August 2013

Find text on a string with jquery

Find text on a string with jquery

i have a problem with jquery condition.
Let me show you the code.
Here i have the "filter" bar:
<div id="filter_menu">
<label>Filter By:</label>
<ul>
<li>
<a href="#" tags="all">ALL</a>
</li>
<li>
<a href="#" tags="audio" class="filterFunction">audio</a>
</li>
<li>
<a href="#" tags="video" class="filterFunction">video</a>
</li>
<li>
<a href="#" tags="other" class="filterFunction">other</a>
</li>
</ul>
</div>
and here my content list that i want to filter by the option in the bar:
<ul>
<li tags="audio video" class="li_item">
content
</li>
<li tags="video" class="li_item">
content
</li>
<li tags="audio" class="li_item">
content
</li>
<li tags="video other" class="li_item">
content
</li>
<li tags="audio other" class="li_item">
content
</li>
<li tags="other" class="li_item">
content
</li>
</ul>
now there is the jQuery snippet:
$(".filterFunction").click(function () {
categoryFilter = $(this).attr("tags");
$('.item_li').each(function () {
if ($(this).attr("tags") == categoryFilter) {
alert('true');
}
else {
alert('false');
}
});
});
HERE THE PROBLEM: with contents that have more than one "tag" in the
attribute tags are never true! i need a condition that become true when
one of the "tag" it's find in the attribute tags!!!
Please someone can help me!!
Thanks a lot! and sorry for my english :)

No comments:

Post a Comment