HTML DOM value Property
The DOM value property in HTML is used to set or return the value of any attribute.
Syntax:
- It returns the attribute value.
attribute.value
- It is used to set a value to the property.
attribute.value = value
Property Value:
- value: It defines the value of the attribute.
Return Value: It returns a string value that represents the value of the attribute.
Example: The below program illustrates the DOM value property in HTML:
HTML
<!DOCTYPE html> < html > < head > < title > DOM Value Property </ title > <!-- script to change property value --> < script > function myFunction() { let x = document.getElementsByTagName("IMG")[0]; x.getAttributeNode("src").value = "https://media.w3wiki.net/wp-content/uploads/icon1.png"; } </ script > </ head > < body style = "text-align:center" > < h1 style = "color:green;" > w3wiki </ h1 > < h2 >DOM Value Property</ h2 > < img src = "https://media.w3wiki.net/wp-content/uploads/icon2.png" width = "180" height = "180" > < p > Click the button to change the value of attribute "src" of the image. </ p > <!-- Button to change DOM value property --> < button onclick = "myFunction()" > Try it </ button > </ body > </ html > |
Output:
Supported Browsers: The browser supported by DOM value property are listed below:
- Google Chrome 62 and above
- Edge 14 and above
- Internet Explorer not supported
- Firefox 22 and above
- Opera 49 and above
- Safari 10 and above
Contact Us