How to change an img element's alt text using JavaScript

setAttribute has two arguments: the attribute name and the attribute value. You can set any attribute of any element using the setAttribute method.”

Mozilla

alt is a property of the image element, so the JavaScript code for changing an img’s alt text becomes:

myimg.setAttribute('alt', "New alt text");