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

[DOM_Document] JS - normalize() 메서드 - 공백제거후, 인접텍스트노드 합치기 (document경우)

document.normalize() 예제

 

<style>

#cc {

  font-size: 20px;

  color: red;

}

</style>


<body onload="norTextNode()">


<button onclick="addTextNode()">Text노드 추가</button>

<button onclick="normalizeNode()">문서 정상화 (Normalize)</button>

<p>이 웹문서는 <span id="cc">1</span> 개 자식노드 보유</p>


<script>

function addTextNode() {

  var x = document.createTextNode(" 또 클릭!! ");

  var y = document.body;

  y.appendChild(x);

  var x = document.getElementById("cc");

  x.innerHTML = y.childNodes.length;

}


function normalizeNode() {

  document.normalize();

  var x = document.body;

  var y = document.getElementById("cc");

  y.innerHTML = x.childNodes.length;

}

</script>

 

결과보기

 

※ 공백 : text 노드로 간주됨.


분류 제목
DOM_Event JS - toggle 이벤트 (= ontoggle 속성) - <details> 요소 (열기/닫기) 시 발생 …
DOM_Event JS - touchcancel -
DOM_Event JS - touchend 이벤트 (= ontouchend 속성) - 손가락 뗄 때 이벤트 발생 (= 터치이벤…
DOM_Event JS - touchmove -
DOM_Event JS - touchstart 이벤트 - 사용자가 요소를 터치할 때 실행 (= touchstart이벤트 = 터…
DOM_Event JS - transitionend -
DOM_Event JS - unload 이벤트 (= onunload 속성) - 사용자가 웹문서 닫을때 JS실행 (= 언로드 이…
DOM_Event JS - volumechange -
DOM_Event JS - waiting -
DOM_Event JS - wheel 이벤트 (= onwheel속성) ★ - 마우스휠 스크롤 이벤트
DOM_Event JS - AltKey -
DOM_Event JS - altKey -
DOM_Event JS - animationName -
DOM_Event JS - bubbles 속성 - 이벤트확산여부판별 (= 확산이벤트판별 = 버블즈속성, IE9)
DOM_Event JS - button -
DOM_Event JS - buttons -
DOM_Event JS - cancelable -
DOM_Event JS - charCode -
DOM_Event JS - changeTouches -
DOM_Event JS - clientX 속성 - 현재창 기준 마우스커서 수평 좌표 위치 (= clientX속성 = 클라이언트…
35/67
목록
찾아주셔서 감사합니다. Since 2012