• 회원가입
  • 로그인
  • 구글아이디로 로그인

[DOM_Element] JS - previousElementSibling 속성 - 바로이전 형제요소 (= previousElementSibling속성 = 프리비어스엘러먼트시블링속성) (IE9 이상

previousElementSibling 예제 - 지정요소 앞 형제요소의 내용 가져오기

 

<ul>

    <li id="site">홈짱닷컴</li>

    <li id="host">Homzzang.com</li>

</ul>


<button onclick="homzzang()">클릭</button>


<p id="demo"></p>


<script>

function homzzang() {

  var x = document.getElementById("host").previousElementSibling.innerHTML; 

  document.getElementById("demo").innerHTML = x;

}

</script>

 

결과보기

결과값: 홈짱닷컴

※ previousSibling 속성과는 달리 <li>요소간 사이에 공백이 있어도 됨.

 

previousElementSibling 예제 - 버튼 클릭 시 버튼 앞 오디오 재생

 

<figure>

    <figcaption>샘플 오디오 듣기:</figcaption>

    <audio  controls src="https://ccrma.stanford.edu/~jos/mp3/harpsi-cs.mp3">

            <a href="https://ccrma.stanford.edu/~jos/mp3/harpsi-cs.mp3">

                audio 다운로드

            </a>

    </audio>

    <button onclick="this.previousElementSibling.play();">play</button>

</figure>

 

결과보기



분류 제목
DOM_Event JS - inputType -
DOM_Event JS - isComposing -
DOM_Event JS - isTrusted -
DOM_Event JS - key 속성 -
DOM_Event JS - key 속성 -
DOM_Event JS - keyCode 속성 - 눌린 키보드키 유니코드 (= onkeypress, onkeydown, on…
DOM_Event JS - location -
DOM_Event JS - lengthComputable -
DOM_Event JS - loaded -
DOM_Event JS - metaKey -
DOM_Event JS - metaKey -
DOM_Event JS - MovementX -
DOM_Event JS - MovementY -
DOM_Event JS - newValue -
DOM_Event JS - newURL -
DOM_Event JS - offsetX 속성 - x좌표 (= 가로좌표 = 가로축좌표 = offsetX속성 = 오프셋엑스속성)
DOM_Event JS - offsetY 속성 - y좌표 (= 세로좌표 = 세로축좌표, offsetY속성, IE6)
DOM_Event JS - oldValue -
DOM_Event JS - oldURL -
DOM_Event JS - onemptied -
37/67
목록
찾아주셔서 감사합니다. Since 2012