0

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 :)

http://jsfiddle.net/uNAXC/

2
  • Did not understand. Why can't you use Javascript conditional operators (&& for AND, || for OR, ~ for NOT)? Commented Jul 13, 2012 at 23:16
  • I could but Im looking for a cleaner fix Commented Jul 13, 2012 at 23:35

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

Comments

0

You need to have a string storing your selector filter, then use it:

http://jsfiddle.net/uNAXC/2/

I put a div inside so you can see the actual selector string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.