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

回答編集履歴

1

修正

2015/12/08 03:14

投稿

liguofeng29
liguofeng29

スコア803

answer CHANGED
@@ -2,21 +2,54 @@
2
2
  <script type="text/javascript" src="jquery-1.10.2.js"></script>
3
3
  <script type="text/javascript">
4
4
  $(function(){
5
+
6
+
7
+ $ele = $(".hoge_child");
8
+ $ele.each(function(index, child) {
5
- // 要素取得
9
+ $child = $(child);
10
+
6
- if ( $(".hoge_child > ul > li").length == 0 ) {
11
+ if ( $child.find("ul > li").length == 0 ) {
7
-
8
- $(".hoge_parent").hide();
12
+ $child.parent(".hoge_parent").hide();
9
- }
13
+ }
14
+
15
+ });
16
+
10
17
  });
11
18
  </script>
12
19
  <div class="hoge_parent">
13
20
  <h4>…</h4> or <h3>…</h3>
14
21
  <div class="hoge_child">
15
22
  <ul>
16
-
23
+
17
24
  </ul>
18
25
  </div>
19
26
  </div>
27
+
28
+
29
+ <div class="hoge_parent">
30
+ <h4>…</h4> or <h3>…</h3>
31
+ <div class="hoge_child">
32
+ <ul>
33
+ <li>…</li>
34
+ <li>…</li>
35
+ <li>…</li>
36
+ <li>…</li>
37
+ </ul>
38
+ </div>
39
+ </div>
40
+
41
+
42
+ <div class="hoge_parent">
43
+ <h4>…</h4> or <h3>…</h3>
44
+ <div class="hoge_child">
45
+ <ul>
46
+ <li>…</li>
47
+ <li>…</li>
48
+ <li>…</li>
49
+ <li>…</li>
50
+ </ul>
51
+ </div>
52
+ </div>
20
53
  ```
21
54
 
22
55
  こちらで試してください。