0

I have a group of items with a data attribute that contains an array of categories:

<div class="result" data-categories="category-1, category-2, category-3" data-type="logo" data-preview="images/previews/preview.jpg">

I'm having trouble selecting elements WITHOUT the value that I'm passing in, from the data-categories group.

$(".media-results .result:not([data-categories*=" + val + "])");

This seems to work ok, but when I change the select element that uses this selector, I get strange, undesirable results(the selector seems to run infinitely and the page keeps hiding and showing elements at random).

Any help from anyone?


Edit: here is the function that the select passes the value to:

allResults.animate({
        opacity: 0
    }, 500, function(){
        console.log("Change triggered. All results hidden.");
        notSelected.hide(50, function(){
            console.log("Unwanted items hidden");
            selected.show().animate({ opacity: "1" }, 500);
        });
    });
2
  • "array of categories" -> list of categories -- I suspect the issue has nothing to do with the above code, but with the code you're handling the select with. Commented Apr 17, 2013 at 15:44
  • The select only exists to pass a value to the "filter" function, which I've added to the question. I have no trouble getting and passing the value from the select, I am having problems using that value to select the correct elements. Commented Apr 17, 2013 at 15:56

1 Answer 1

1

You can use filter()

elements = $(".media-results .result").filter(function(){
    return $(this).data("categories").indexOf(val) == -1
});
Sign up to request clarification or add additional context in comments.

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.