Ok. Here is what I do to change the image src of some list items in my body script. as default, these list items load a different image. WHat I try to do is to check for the text in my urlArray, and then set the image src to somethingelse.png. I think the folllowing loop which runs at the end of the body section changes the source, but it does not change the actual picture. How can I make sure that it changes the picture as well?
for (var i=0; i<urlArray.length; i++) {
var imgname = "listimg";
if (urlArray[i][1]==="fi"){
var currentname = imgname.concat(i);
if(document.getElementById(currentname) ) //check if element exists
{
document.getElementById(currentname).src= "write.png";
//for debugging; delete from production code.
console.log(document.getElementById(currentname).src); //should write "write.png" to console.
}
}
}
Thank you for your answers and comments, forgive me for being a rookie..
Also some li items from my html:
<li>
<a href="#" onclick="datasent(1);"><img src="mcicon.png" id="listimg0" alt="Gummy Bears" /><span id="test1score" class="ui-li-count">12</span>
<h2 id="testname0"> Test Name 0</h2>
<p id="testexp0">Test Explanation 0</p>
</a>
</li>
<li>
<a href="#dog" onclick="datasent(2);"><img src="mcicon.png" id="listimg1" alt "Min Pin" />
<h1 id="testname1">Test Name 1</h1>
<p id="testexp1">Test Explanation 1</p>
</a>
</li>