Node.nextSibling
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 7ì.
ì½ê¸° ì ì© ìì±ì¸ Node.nextSibling ì ë¶ëª¨ì childNodes 목ë¡ìì ì§ì ë ë
¸ë ë°ë¡ ë¤ìì ìë ë
¸ë를 ë°ííê±°ë ì§ì ë ë
¸ëê° í´ë¹ 목ë¡ì ë§ì§ë§ ë
¸ëì´ë©´ null ê°ì ë°íí©ëë¤.
Syntax
nextNode = node.nextSibling;
Notes
Gecko ê¸°ë° ë¸ë¼ì°ì ë ìì¤ ë§í¬ì
ìì 공백ì ëíë´ê¸° ìí´ ë¬¸ì ë´ì í
ì¤í¸ ë
¸ë를 ì½ì
í©ëë¤.
ê·¸ë¬ë¯ë¡ ì를 ë¤ì´ Node.firstChildë Node.previousSiblingì íµí´ì ì»ì ë
¸ëë ìì±ìê° ì»ì¼ë ¤ í ì¤ì ìììë
ë¬ë¦¬ 공백 í
ì¤í¸ ë
¸ë를 참조í ì§ë 모ë¦
ëë¤.
ë ë§ì ì ë³´ë Whitespace in the DOMê³¼ W3C DOM 3 FAQ: Why are some Text nodes empty?를 ë³´ì¸ì.
Example
<div id="div-01">Here is div-01</div>
<div id="div-02">Here is div-02</div>
<script type="text/javascript">
var el = document.getElementById("div-01").nextSibling,
i = 1;
console.log("Siblings of div-01:");
while (el) {
console.log(i + ". " + el.nodeName);
el = el.nextSibling;
i++;
}
</script>
/************************************************** ë¡ëë ë ë¤ìê³¼ ê°ì´ ì½ìì
기ë¡ë©ëë¤. : Siblings of div-01 1. #text 2. DIV 3. #text 4. SCRIPT
**************************************************/
ìì ììì #text ë
¸ëë íê·¸ ì¬ì´ì ë§í¬ ì
ìì ê³µë°±ì´ ë°ìíë DOMì ì½ì
ëë©° ( ì¦ ììì ë«ê¸° íê·¸ì ë¤ì íê·¸ì ì´ê¸° íê·¸ ì¬ì´ì ììµëë¤ ) document.write 구문ì ìí´ ì½ì
ë ììê°ì ê³µë°±ì´ ìì±ëì§ ììµëë¤.
nextSibling ì ì¬ì©íì¬ DOMì íì í ë, DOMì í
ì¤í¸ ë
¸ë를 í¬í¨ìí¬ ì ìì´ì¼ í©ëë¤. ë
¸í¸ ì¹ì
ì 리ìì¤ë¥¼ 참조íì¸ì.