jquery passing $(this) to other functions

后端 未结 1 1668
有刺的猬
有刺的猬 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)
提交回复
热议问题