Looking at your code you do:
var names = ("1200voc")
then try to access names
as an array.
So this:
for (x = 0; x < names.length; x++) {
var prof = document.getElementById(names[x]);
prof.src="https://stackoverflow.com/questions/48342902/engine/images/proffesion/" + names[x] + '.png';
}
Means that names[0]
will return 1
, names[1]
will return 2
, names[2]
will return 0
and so on…
Now there’s is no element with id of 1
or 2
… so when you do:
var prof = document.getElementById(names[x]);
you get your error.
What you want is an array of names, so what you should do is:
var names = ["1200voc"]
This way you can properly loop through names
as an array in the format you want.
solved Uncaught TypeError: Cannot set property ‘src’ of null while changing SRC of img [closed]