- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM nodeValue Property
The HTML DOM nodeValue property returns/sets a string corresponding to the value of the node.
Following is the syntax −
Returning string value
Node.nodeValue
Here, the return value can be the following −
- Value as ‘null’ for document nodes & element nodes
- Value as ‘value’ of the attribute for attribute nodes
- Value as content for text nodes and comment nodes
Set nodeValue to a string value
Node.nodeValue = string
NOTE: Whitespaces are considered as text nodes only.
Let us see an example of HTML DOM nodeValue property −
Example
<!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>
Output
Before clicking ‘Confirm for Bina’ button −
After clicking ‘Confirm for Bina’ button −
- Related Articles
- What is nodeValue property in JavaScript HTML DOM?
- HTML DOM accessKey Property
- HTML DOM activeElement Property
- HTML DOM paddingLeft Property
- HTML DOM id Property
- HTML DOM innerHTML Property
- HTML DOM innerText Property
- HTML DOM parentElement Property
- HTML DOM parentNode Property
- HTML DOM previousSibling Property
- HTML DOM previousElementSibling Property
- HTML DOM readyState Property
- HTML DOM ownerDocument Property
- HTML DOM scrollHeight Property
- HTML DOM scrollWidth Property

Advertisements