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

回答編集履歴

3

リファクタ

2015/12/08 03:12

投稿

ikki57
ikki57

スコア290

answer CHANGED
@@ -28,7 +28,6 @@
28
28
  ```
29
29
 
30
30
  上記サンプルコードに対し、下記コードでテスト済です。
31
- jQueryを使っています。
32
31
 
33
32
  ```javascript
34
33
  $(function() {
@@ -36,7 +35,7 @@
36
35
  // '.hoge_parent' のオブジェクトを取得し、ループ処理します
37
36
  $('.hoge_parent').each(function(index, elm) {
38
37
  // hoge_parent配下のli要素数を取得する
39
- listLength = $(elm).find('.hoge_child > ul > li').length;
38
+ listLength = $(this).find('.hoge_child > ul > li').length;
40
39
  // list length がなければ非表示にします
41
40
  if (!listLength) {
42
41
  // 非表示にするだけなら

2

テキスト追加

2015/12/08 03:12

投稿

ikki57
ikki57

スコア290

answer CHANGED
@@ -27,18 +27,23 @@
27
27
  </div>
28
28
  ```
29
29
 
30
+ 上記サンプルコードに対し、下記コードでテスト済です。
31
+ jQueryを使っています。
32
+
30
33
  ```javascript
34
+ $(function() {
31
- var listLength;
35
+ var listLength;
32
- // '.hoge_parent' のオブジェクトを取得し、ループ処理します
36
+ // '.hoge_parent' のオブジェクトを取得し、ループ処理します
33
- $('.hoge_parent').each(function(index, elm) {
37
+ $('.hoge_parent').each(function(index, elm) {
34
- // hoge_parent配下のli要素数を取得する
38
+ // hoge_parent配下のli要素数を取得する
35
- listLength = $(elm).find('.hoge_child > ul > li').length;
39
+ listLength = $(elm).find('.hoge_child > ul > li').length;
36
- // list length がなければ非表示にします
40
+ // list length がなければ非表示にします
37
- if (!listLength) {
41
+ if (!listLength) {
38
- // 非表示にするだけなら
42
+ // 非表示にするだけなら
39
- $(this).hide();
43
+ $(this).hide();
40
- // DOMごと削除するなら
44
+ // DOMごと削除するなら
41
- // $(this).remove();
45
+ // $(this).remove();
42
- }
46
+ }
43
- })
47
+ })
48
+ });
44
49
  ```

1

コメント修正

2015/12/08 03:06

投稿

ikki57
ikki57

スコア290

answer CHANGED
@@ -28,12 +28,12 @@
28
28
  ```
29
29
 
30
30
  ```javascript
31
- // hoge_parentをループする
32
31
  var listLength;
32
+ // '.hoge_parent' のオブジェクトを取得し、ループ処理します
33
33
  $('.hoge_parent').each(function(index, elm) {
34
34
  // hoge_parent配下のli要素数を取得する
35
35
  listLength = $(elm).find('.hoge_child > ul > li').length;
36
- // list length がなければ非表示にす
36
+ // list length がなければ非表示にしま
37
37
  if (!listLength) {
38
38
  // 非表示にするだけなら
39
39
  $(this).hide();