You already did this when you changed the in-line style of an element because that is an attribute with the styles as values.  You can also change any other attribute.

To try this you will need two images:

You have just changed the value of the src attribute and therefore the image changes.  You can change the value of any attribute in this same way.  Having changed the image you should now change the alt to describe the new image and not the old one.  Do that.  To test it remove the second image file or deliberately miss-spell the file name in the JavaScript and the alt will be displayed instead of the missing image.  Fix the missing image once you know the alt is working.