How can I change the src
attribute of an img
tag using javascript?
In this case, as you want to change the src
of the first value of your element, you have no need to build up a function. You can change this right in the element:
You have several ways to do this. You can also create a function to automatize the process:
function changeSrc(p, t) { /* where p: Parent, t: ToSource */
p.firstChild.src = t
}
Then you can: