jquery passing $(this) to other functions

后端 未结 1 1667
有刺的猬
有刺的猬 2021-01-22 05:03

High!

What i want to do is the following: i have a table with a onclick attached to a link that resides in the table of an even row. every odd row is hidden. on a click

相关标签:
1条回答
  • 2021-01-22 05:44

    The problem is this:

    $(this).click(function(){
      attachHideMyChildren();
    });
    

    When you call a function that way this becomes window. Instead do this:

    $(this).click(attachHideMyChildren);
    

    Also, you're adding click() handlers without removing the old ones.

    That being said, there is an easier way of doing this.

    $("a.version").click(function() {
      var next = $(this).closest("tr").next();
      if (next.is(":hidden")) {
        $.get($(this).attr("href"), function(sData) {
          next.find("td:first").html(sData);
          next.show();
        });
      } else {
        next.hide();
      }
      return false;
    });
    

    should about do it.

    0 讨论(0)
提交回复
热议问题