...and optimised further to reduce redundant jquery object creation
and property look-ups:
$(".toggle_cat a").each(function(){
$(this)
.attr("title", "Click here to exclude this cat")
.click(function(){
$(this).toggleClass("selected");
var rel = this.rel;
$("." + rel).toggle(
function() { $("." + rel).hide('slow'); },
function() { $("." + rel).show('fast'); }
);
});
});
Joel.
On 04/04/2007, at 10:21 PM, Joel Birch wrote:
I guess that inside the anonymous functions within toggle, 'this'
is no longer the 'this' that you intend it to be. Try setting a
variable to the 'this' you want outside of the toggle instead -
like so:
$(".toggle_cat a").each(function(i){
$(this).attr("title", "Click here to exclude this cat");
$(this).click(function(event){
$(this).toggleClass("selected");
var self = this; /* saves your 'this' for use in the toggle */
$("." + this.rel).toggle(
function() { $("." + self.rel).hide('slow'); },
function() { $("." + self.rel).show('fast'); }
);
});
});
Joel.
On 04/04/2007, at 10:16 PM, Sebastián V. Würtz wrote:
$(".toggle_cat a").each(function(i){
$(this).attr("title", "Click here to exclude this cat");
$(this).click(function(event){
$(this).toggleClass("selected");
$("." + this.rel).toggle(
function() { $("." + this.rel).hide('slow'); },
function() { $("." + this.rel).show('fast'); }
);
});
});