JavaScript/Changing Elements
From Wikibooks, open books for an open world
|
|
A reader has identified this page or section as an undeveloped draft or outline. You can help to develop the work, or you can ask for assistance in the project room. |
In order to change an element, you use its argument name for the value you wish to change. For example, let's say we have a button, and we wish to change its value.
<input type="button" id="myButton" value="I'm a button!">
Later on in the page, with JavaScript, we could do the following to change that button's value:
myButton = document.getElementById("myButton"); //searches for and detects the input element from the 'myButton' id myButton.value = "I'm a changed button"; //changes the value
To change the type of input it is (button to text, for example) then use:
myButton.type = "text"; //changes the input type from 'button' to 'text'.