Node.previousSibling
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.previousSibling ì ì½ê¸°ì ì© ìì±ì´ë©° íì¬ í¸ì¶íë ë
¸ëê° ìí´ ìë ë¶ëª¨ì childNodes 목ë¡ìì í¹ì ìì ë
¸ë를 리í´íê±°ë childNodes 목ë¡ì 첫ë²ì§¸ ë
¸ëì¼ ê²½ì° Nullê°ì 리í´í©ëë¤.`
Syntax
previousNode = node.previousSibling;
Example
// <a><b1 id="b1"/><b2 id="b2"/></a>
alert(document.getElementById("b1").previousSibling); // null
alert(document.getElementById("b2").previousSibling.id); // "b1"
Notes
Gecko ê¸°ë° ë¸ë¼ì°ì ë ìì¤ ë§í¬ì
ìì 공백ì ëíë´ê¸° ìí´ ë¬¸ì ë´ì í
ì¤í¸ ë
¸ë를 ì½ì
í©ëë¤.
ê·¸ë¬ë¯ë¡ ì를 ë¤ì´ Node.firstChildë Node.previousSiblingì íµí´ì ì»ì ë
¸ëë ìì±ìê° ì»ì¼ë ¤ í ì¤ì ìììë
ë¬ë¦¬ 공백 í
ì¤í¸ ë
¸ë를 참조í ì§ë 모ë¦
ëë¤.
ë ë§ì ì ë³´ë Whitespace in the DOMê³¼ W3C DOM 3 FAQ: Why are some Text nodes empty?를 ë³´ì¸ì.
To navigate the opposite way through the child nodes list use Node.nextSibling.