What about this (using your coding style to avoid confusion):

$(".toggle_cat a").each(function(i){
        $(this).attr("title", "Click here to exclude this cat");
        $(this).click(function(event){
                $(this).toggleClass("selected");
        });
        var rel = this.rel;
        $(this).toggle({
                function() { $("." + rel).hide('slow'); },
                function() { $("." + rel).show('fast'); }
        });
});

It occurred to me that your previous code is actually merely applying toggle behaviour to other elements when you click a link, not actually running the functions in the toggle, which you may actually want to do. The reason why the simple toggle() worked then would be because toggle has different behaviour depending on whether you pass in functions to it or not.

Does this help?

Joel.


On 04/04/2007, at 11:26 PM, Sebastián V. Würtz wrote:

Before asking for this code I tried to create the variable and use it. I did not optimize it because im noob for this and still I am learning, thanks for the help, nevertheless still it follows without working and I do not have idea because it does not do it

God bless google translator.

This code work

$(".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'); }
    */
  );
 });
});

This code dosnt work

$(".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'); }
  );
 });
});

Reply via email to