I have this small script I'm trying to get working on my webpage, its supposed to filter a bunch of programming videos I'm linking to by running a small and simple javascript as shown below. I want to improve it by making so that it doesen't show the result unless ALL REQUIREMENTS are met. In example if I filter on 'python' and 'easy', i only want results that fits BOTH of those requirements. I hope i made myself understood and I also do believe its a rather simple fix.. Please take a quick look at the code below and respond as fast as possible :)
-
Did not understand. Why can't you use Javascript conditional operators (&& for AND, || for OR, ~ for NOT)?Jay– Jay2012-07-13 23:16:09 +00:00Commented Jul 13, 2012 at 23:16
-
I could but Im looking for a cleaner fixjlodenius– jlodenius2012-07-13 23:35:14 +00:00Commented Jul 13, 2012 at 23:35
Add a comment
|
2 Answers
You should first 'build' your filter, and then apply it.
$('div.tags').delegate('input:checkbox', 'change', function()
{
var $lis = $('.results > li').hide();
var filter = '';
//For each one checked
$('input:checked').each(function()
{
filter += '.' + $(this).attr('rel');
});
$lis.filter(filter).show();
console.log(filter);
}).find('input:checkbox').change();
Comments
You need to have a string storing your selector filter, then use it:
I put a div inside so you can see the actual selector string