回答編集履歴

2

脱字

2016/10/01 12:26

投稿

tama_yn0815
tama_yn0815

スコア143

test CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  if($parentDiv.css('display') == priorityStyle){
22
22
 
23
- return true;//これで、除外したいやつから抜けれる
23
+ return true;//これで、除外したいやつから抜けれる
24
24
 
25
25
  }
26
26
 

1

追記

2016/10/01 12:26

投稿

tama_yn0815
tama_yn0815

スコア143

test CHANGED
@@ -1,3 +1,9 @@
1
+ ---
2
+
3
+ **解決策**
4
+
5
+
6
+
1
7
  ```javascript
2
8
 
3
9
  $(function(){
@@ -8,19 +14,17 @@
8
14
 
9
15
  $('div p').each(function(i, e){
10
16
 
11
- var $this = $(this);.attr('id')
17
+ var $this = $(this);
12
-
13
- var thisId = $this.attr('id');
14
18
 
15
19
  var $parentDiv = $this.parents('div');
16
20
 
17
- if($parentDiv.css("border") == priorityStyle){
21
+ if($parentDiv.css('display') == priorityStyle){
18
22
 
19
23
  return true;//これで、除外したいやつから抜けれる
20
24
 
21
25
  }
22
26
 
23
- $this.attr({id:idNum});
27
+ $this.attr({id: '' + idNum});
24
28
 
25
29
  idNum++
26
30
 
@@ -32,6 +36,48 @@
32
36
 
33
37
 
34
38
 
35
- これで出来ると思います。
39
+ ---
36
40
 
41
+ **解説**
42
+
43
+ ```javascript
44
+
45
+ $('div p').each();
46
+
47
+ ⇒これで繰り返し処理を行う
48
+
49
+ $this.parents('div');
50
+
51
+ ⇒parentsで先祖要素をセレクターで取得
52
+
53
+ if($parentDiv.css('display') == priorityStyle)
54
+
55
+ ⇒ここで、if処理をして、スタイルで非表示の要素は、除外
56
+
57
+ return true;
58
+
59
+ ⇒eachメソッドないでは、for文のcontinue;と同じ動作になります。
60
+
61
+  ※falseを返せば、break;と同じ動作です。
62
+
63
+ $this.attr({id: '' + idNum});
64
+
37
- 詳細は、今から編集追記します
65
+ ⇒attr()プロパティにアクセスします
66
+
67
+ ```
68
+
69
+
70
+
71
+ [parents](http://semooh.jp/jquery/api/traversing/parents/%5Bexpr%5D/)
72
+
73
+ [css](http://semooh.jp/jquery/api/css/)
74
+
75
+ [each](http://semooh.jp/jquery/api/utilities/jQuery.each/object%2C+callback/)
76
+
77
+ [attr](http://semooh.jp/jquery/api/attributes/attr/properties/)
78
+
79
+
80
+
81
+
82
+
83
+ こんな感じ