18
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【jQuery】要素の選択(children,parent,siblings,next,prev)

Last updated at Posted at 2013-12-17

こんにちは。
本日は要素の選択をやっています。

やっていること自体の理解はできているのですが、

どのように使われるのかがちょっとまだ理解できていません。

jQueryでリスト表示とか、あのアコーディオンみたいな
選択メニューの際に使われるのでしょうか。
と、あたりをつけています。

'私'を基点として、学習していくと、
結構理解しやすかったです。

参考:
http://jeek.jp/study/section30/1

<div id="grandparent">祖父
  <div id="parent"><div id="sibling1"></div>
    <div id="sibling2"></div>
    <div id="target">わたし
      <div id="children1">息子</div>
      <div id="children2"></div>
    </div>
    <div id="sibling3"></div>
    <div id="sibling4"></div>
  </div>
</div>

children() ... 各要素内全ての「子」要素を選択
parent() ... 各要素内全ての「親」要素を選択
siblings() ... 各要素内全ての「兄弟」要素 を選択

next() ... 1つ次に来る「兄弟」要素を選択
prev() ... 1つ前に来る「兄弟」要素を選択

ex)
$(function(){
    $("target").next().children().css("color","blue") ;
)}

この場合だと、id="target"要素の次に来る兄弟要素の子要素。
ということなんですね~。
やりかたは理解!

さて選択ができるようになったところで、
どのように活かせるのだろうか~調べてきます。

それでは、これからも宜しくお願いいたします。

18
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?