LoginSignup
0
0

More than 1 year has passed since last update.

$(this)についてまとめました

Posted at

理解が止まったところ

下記のコードで.find('td')が使われているけど、この$(this)はどこを指すのか?

$(function() {
  $('table').find('td').on('click', function(){
    $(this).closest('table').find('td') //追記
  });
});

分かっていたこと
 $(this)はイベントが発生した要素のみを取得する

例:下記の場合はクリックしたp要素

$(function() {
  $('p').on('click', function() {
    $(this).css('color', 'blue');
  });
});

A.(文章化したら解決した)

  1. 「クリックされた<table>内の<td>」を$(this)とする
  2. 「クリックされた<table>内の<td>」の親要素<table>を(.closest('table'))によって取得
  3. <table>の子要素<td>すべてを(.find('td'))によって取得
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0