I have this HTML:
Intermediate steps
→
Try using document.querySelectorAll which returns all of the possible results instead of just the first one. The error you're getting (Uncaught TypeError: Cannot set property 'src' of undefined
) is because querySelector
only returns the first element found, not an array (and elements can't be accessed like arrays).
jQuery (the inspiration for querySelector
and querySelectorAll
) always allows you to access like an array ($('.staticStep img')[0]
works), so this is probably where your confusion stems from.
Quick JSFiddle example: http://jsfiddle.net/j8ZUJ/1/