Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Count filtered list items Reply To: Count filtered list items

#146193
bcintegrity1
Participant

I finally got everything working…and then some! Thankfully, jquery is “easy” to read, so I’ll let the code speak for itself (what the functions are).

$(document).ready(function(){
var $nopestprofessional = $('#nopestprofessional')
var n = $('li.services').length;
if (n < 1) {$nopestprofessional.removeClass('tab').addClass('tab1');
$('#nopestprofessional p').css('marginBottom', '20px');
$('div.servicearea li').css("list-style", "none").css("line-height", "17px");}
else {
jQuery.fn.shuffle = (function(){ 
function ListShuffle(arr) { 
var i = arr.length, r, tempI, tempR; 
if ( i === 0 ) {return arr;} 
while ( i-- ) { 
r = Math.floor(Math.random() * (i + 1));
tempI = arr[i];
tempR = arr[r];
arr[i] = tempR;
arr[r] = tempI;} 
return arr;}
return function(s) {return this.each(function(){var container = jQuery(this); 
container.append(ListShuffle(container.find(s))
);
});
}; 
})();
$('.blank').hide();
$('#list').shuffle('li.services');
$("li.cover").appendTo("#list");
$("li.pest_control").appendTo("#list");
$('li.services:gt(14)').hide();
$('#button')
.bind('click',function(e) {
e.preventDefault();
$("li.pest_control").hide();})
.bind('click',function(e) {
$('.cover').addClass('showcover');})
.bind('click',function(e) {
$('.coverm h2').animate({"color": "#ff7700", "textShadow": "2px 2px 3px #111111"},{duration: 2400})
.animate({"color": "#ffffff", "textShadow": "0px 0px 10px #ffffff"},{queue: true, duration: 1000})
.animate({"color": "#ff7700", "textShadow": "2px 2px 3px #111111"},{queue: true, duration: 1500});})
.bind('click',function(e) {
$('.flipper').addClass('top');})
.bind('click',function(e) {
$('.flipbutton').addClass('flipmenu');})
$('.flipbutton a').click(function(e){
e.preventDefault();
$('.flipper').toggleClass('top');});
;}
$('div.servicearea li').css("list-style", "none").css("line-height", "17px");
$('#filter a').click(function(e){
e.preventDefault();
$('#filter a').removeClass('active');
var filter = $(this).attr('id');
var $filteredItems = $("." + filter);
if ($filteredItems.length == 0) {$(this).addClass('active');
$nopestprofessional.removeClass('tab').addClass('tab1').show();
$('#nopestprofessional h2').replaceWith('<h2>There are currently no listings for this service in your area.</h2>');
$('#nopestprofessional p').replaceWith('

Find pest professionals from a neighboring city/county who may offer this service in your area.

'); $('#nopestprofessional p').css('marginBottom', '20px'); } else { $(this).addClass('active'); $('#list li').show(); $('#list li:not(.' + filter + ')').hide(); $nopestprofessional.removeClass('tab1').addClass('tab');} }); });

The live site: http://integritycontractingofva.com/Pest-Control-in-Chesterfield%2C-VA—Midlothian%2C-VA—Chester%2C-VA—Moseley%2C-VA.php

Now I’ve gotta debug for IE.