||This page or section is an undeveloped draft or outline.
You can help to , or you can ask for assistance in the project room.
Here, the srcattribute of an image is changed so when the script is called, it changes the picture from myPicture.jpg to otherPicture.jpg.
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!">
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), use:
myButton.type = "text"; //changes the input type from 'button' to 'text'.
Another way to change or create an attribute is to use a method like element.setAttribute("attribute", "value") or element.createAttribute("attribute", "value"). Use setAttribute/tt> to change a attribute that has been defined before.
But use createAttribute, if you want to set a value that hasn't been defined before.
var e = document.createElement('div'); //Make a div element (we also could have made it with HTML) e.createAttribute("id", "myDiv"); //Set the id to "myDiv"
Manage research, learning and skills at defaultLogic. Create an account using LinkedIn or facebook to manage and organize your Digital Marketing and Technology knowledge. defaultLogic works like a shopping cart for information -- helping you to save, discuss and share.