回答編集履歴

1

説明を追加

2019/08/15 09:54

投稿

moredeep
moredeep

スコア1507

test CHANGED
@@ -1,3 +1,41 @@
1
1
  `$('p#a').next()`は、`$('p#a')`の全結果ノードの次の要素を列挙します。そのため、`$('p#a').next()[0].tagName`とすれば目的の値は取れるでしょう。
2
2
 
3
3
  なお、`$('p#a')[0]`は、`document.getElementById("a")`と同じになりますので、`document.getElementById("a").next()`となり、next関数が無いと怒られます。
4
+
5
+ DOMオブジェクトとJQUeryオブジェクトはいつの間にか入れ替わっていたりするので、慣れないうちはオブジェクト自体をconsole出力するといいと思います。
6
+
7
+
8
+
9
+ 例えば・・・
10
+
11
+ ```
12
+
13
+ $('p.test'); // これはaとc
14
+
15
+ $('p.test').next(); // これはbとd
16
+
17
+ $('p.test').next().prev(); // これはaとc($('p.test')と一緒)
18
+
19
+ $('p.test')[0]; // これはdocument.getElementById("a")と一緒
20
+
21
+ $('p.test')[1]; // これはdocument.getElementById("c")と一緒
22
+
23
+ $('p.test').next()[0] // これはdocument.getElementById("b")と一緒
24
+
25
+ $('p.test').next()[1] // これはdocument.getElementById("d")と一緒
26
+
27
+
28
+
29
+ // ...
30
+
31
+
32
+
33
+ <p id="a" class="test"></p>
34
+
35
+ <p id="b"></p>
36
+
37
+ <p id="c" class="test"></p>
38
+
39
+ <p id="d"></p>
40
+
41
+ ```