HTML DOM nodeValue 속성은 노드의 값에 해당하는 문자열을 반환/설정합니다.
다음은 구문입니다 -
문자열 값 반환
Node.nodeValue
여기서 반환 값은 다음과 같을 수 있습니다. -
- 문서 노드 및 요소 노드의 경우 'null' 값
- 속성 노드에 대한 속성의 '값'으로서의 값
- 텍스트 노드 및 주석 노드의 콘텐츠로서의 가치
nodeValue 설정 문자열 값으로
Node.nodeValue = string
참고:공백은 텍스트 노드로만 간주됩니다.
HTML DOM nodeValue의 예를 살펴보겠습니다. 속성 -
예시
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM nodeValue</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
ul{
width: 30%;
margin: 0 auto;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-DOM-nodeValue</legend>
<h3>Students</h3>
<ul>
<li>Adam</li>
<li>Alex</li>
<li>Bina</li>
<li>Eden</li>
<li>Rajesh</li>
<li>Zampa</li>
</ul>
<input type="button" onclick="checkForBina()" value="Confirm for Bina">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var studentList = document.getElementsByTagName("li");
var status = 'not Present';
function checkForBina() {
for(var i=0; i<studentList.length; i++){
if(studentList[i].childNodes[0].nodeValue === 'Bina')
status = 'Present';
}
divDisplay.textContent = 'Bina is '+status;
}
</script>
</body>
</html> 출력
'Bina 확인을 클릭하기 전에 ' 버튼 -

'비나 확인을 클릭한 후 ' 버튼 -
