Forum Moderators: open

Message Too Old, No Replies

jquery filter?

         

ads112001

3:07 pm on Dec 2, 2010 (gmt 0)

10+ Year Member



trying to toggle content using this jquery script
$(document).ready(function() {
$('ul#legend a').click(function() {
$('ul#legend .current').removeClass('current');
$(this).parent().addClass('current');

var filterVal = $(this).text().toLowerCase().replace(' ','-');

if(filterVal == 'all-events') {
$('#calendarContent p.hidden').fadeIn('slow').removeClass('hidden');
} else {
$('#calendarContent p').each(function() {
if(!$(this).hasClass(filterVal)) {
$(this).fadeOut('normal').addClass('hidden');
} else {
$(this).fadeIn('slow').removeClass('hidden');
}
});
}

return false;
});
});


This works but when the legend value is more than 2 words long it doesn't seem to work.

Fotiman

3:31 pm on Dec 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The replace method only replaces the first instance unless you tell it to replace all with the g flag. Try this:


var filterVal = $(this).text().toLowerCase().replace(/\s/g,'-');

ads112001

3:38 pm on Dec 2, 2010 (gmt 0)

10+ Year Member



you're my hero!