-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjfilter.js
More file actions
26 lines (21 loc) · 722 Bytes
/
jfilter.js
File metadata and controls
26 lines (21 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(function($){
$.fn.jfilter = function(options) {
var settings = $.extend({
target: '.filter-target'
},
options);
this.off('keyup').on('keyup', function(event) {
toggleTargets(this.value, $(settings.target + ' .filter-item'));
});
function toggleTargets(value, elements) {
elements.each(function() {
if(value !== "" && !$(this).html().match(new RegExp(value + "+", 'gi'))) {
$(this).hide();
} else {
$(this).show();
}
});
}
return this; //chaining;
}
})(jQuery);