Created
May 27, 2021 06:19
-
-
Save alt-karate/44a7b51fcd14df468719b1c0c91ca25f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function($) { | |
//data-hrefの属性を持つtrを選択しclassにclickableを付加 | |
$('tr[data-href]').addClass('clickable') | |
//クリックイベント | |
.click(function(e) { | |
//e.targetはクリックした要素自体、それがa要素以外であれば | |
if(!$(e.target).is('a')){ | |
//その要素の先祖要素で一番近いtrの | |
//data-href属性の値に書かれているURLに遷移する | |
window.location = $(e.target).closest('tr').data('href');} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tr data-href="http://ja.wikipedia.org/wiki/%E6%9D%B1%E4%BA%AC"> | |
<td>東京</td> | |
<td>とうきょう</td> | |
<td>Tokyo</td> | |
<td>日本の事実上の首都がある</td> | |
<td><a href="#">ダミーリンク</a></td> | |
</tr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment