OK, it's friday and I'm really tired:
OK, it's nearly friday again (yes, one week later!) and I'm getting even more tired:
How do I find all elements with on of the entries from an array.
How do I make a freakin complicated jQuery selector that keep sending me in the fence over and over again?
My array (of selectors):
["one", "two", "three", "four", "five"]
My elements:
<div data-filters="one two three four five"></div>
<div data-filters="one three four five"></div>
<div data-filters="one two four five"></div>
<div data-filters="two three five"></div>
<div data-filters="one four five"></div>
<div data-filters="two three four five"></div>
<div data-filters="four five"></div>
What is the most optimized way of getting ALL elements that contain ONE of the strings in the array?
I'm already filtering using:
$(this).next().find('tr.normal').? ... how to extend selector using array
I have a range of divs which contain table of rows with data-filtertypes in the form of space separated strings:
<div class="category">
<table>
<tr data-filtertypes="one three five"><td></td></tr>
</table>
</div>
<div class="category">
<table>
<tr data-filtertypes="one two four"><td></td></tr>
</table>
</div>
<div class="category">
<table>
<tr data-filtertypes="three five"><td></td></tr>
</table>
</div>
I initially hide all categories:
$('.category').hide()
I then want to show categories (and rows) based on the user typing into a field (search text on multiple other attributes not shown here for brevity), but first I want to reduce the collection by filtering using buttons with matching names - if any are selected.
var any_filters = ["two", "four"];
$('.category').hide().filter(
if ( any_filters.length > 0 ) {
// Here I (think) I need $.each() to iterate element using the any_filters array ... I want to 'return' a reduced selection set I can then pass on to another piped filter()
// Problem with return here!?
$.each( any_filters, function ( index, value ) {
return $( '[data-filtertypes*="' + value + '"]' );
});
}
).filter(
// What is passed into this filter?
console.log( "?", this );
)
Is this approach totally screwed, or am I on the right track? And what pieces am I missing in making this 'tactic' work?
"one"(string) or atleast one element from array. Aah. I'm confused. On a friday...