teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード修正

2016/03/14 06:34

投稿

orange0190
orange0190

スコア1698

answer CHANGED
@@ -1,10 +1,12 @@
1
1
  後から追加された要素にもイベントを設定したい場合には、次のように書くといいと思います。
2
2
  ```javascript
3
+ $(function(){
3
- $(document).on("mouseenter", ".thumbnail", function(e) {
4
+ $(document).on("mouseenter", ".thumbnail", function(e) {
4
- $(this).find('.operation_list').css('display', 'block');
5
+ $(this).find('.operation_list').css('display', 'block');
6
+ });
7
+ $(document).on("mouseleave", ".thumbnail", function(e){
8
+ $('.operation_list').css('display', 'none');
9
+ });
5
10
  });
6
- $(document).on("mouseleave", ".thumbnail", function(e){
7
- $('.operation_list').css('display', 'none');
8
- });
9
11
  ```
10
12
  `hover`は`on`を使うと書けないので、このような形になります。