- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 value Property
The HTML DOM value property returns a string corresponding to the value of the attribute of an element.
Following is the syntax −
Returning string value
elementAttribute.value
Let us see an example of HTML DOM value property −
Example
<!DOCTYPE html> <html> <head> <title>HTML DOM value</title> <style> * { padding: 2px; margin:5px; } form { width:70%; margin: 0 auto; text-align: center; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>HTML-DOM-value</legend> <img src="https://www.tutorialspoint.com/jdbc/images/jdbc-mini-logo.jpg"> <div id="divDisplay">What is src attribute's value?</div> <input type="button" value="Get Answer" onclick="getAnswers()"> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); function getAnswers() { var ans = document.getElementsByTagName('img')[0].attributes[0].value; divDisplay.textContent = 'src attribute has a value '+ans; } </script> </body> </html>
Output
Before clicking ‘Get Answer’ button −
After clicking ‘Get Answer’ button −
Advertisements