How to determine the img source using Jquery/Javascript on pageload?
<p>I've gone through many SO threads, I can't seem to find a working solution.</p>

<p>All I'm trying to do is when the page loads, the site pushes all elements with the ".home" class into the array arr. Then, the script parses through each element in the array and tries to match it with a string. For example, right now all I have is a check to see if the element has the words "Boston" in it, in which case I want to make the image source for ".homeimage" the linked imgur link. I'm aware it's not wise to host images on imgur for these reasons, I'm just trying to check if it works. Below this test I have some redundant code I was practicing with that I found in a SO thread, changing the color of text to gray. I figured changing attributes is the same.</p>

<p>my html code:</p>

<pre><code>&lt;td colspan = "3"width=400px class = "home"&gt;&lt;b&gt;&lt;%= game.home %&gt;&lt;/b&gt;&lt;/td&gt;

&lt;td colspan = "3"&gt;&lt;img style="width:150px;height:128px;" class = "homeimage"&gt;&lt;/td&gt;
</code></pre>

<hr>

<p>my javascript/jquery code:</p>

<blockquote>
<pre><code>&lt;script&gt;          
var arr=[];
$(document).ready( function(){
     $(".home").each(function(){ arr.push($(this));});
     for(i = 0; i &lt; arr.length; i++){
         if(arr[i].indexOf "Boston" != -1){
            $('.homeimage img').attr("src","http://i.imgur.com/s5WKBjy.png");
         }
     }
 $.each(arr,function(key,val){
 val.css('color','gray')}); //something redundant i was testing out
 });
 &lt;/script&gt;
</code></pre>
  
  <hr>
</blockquote>

<p>additional questions:</p>

<p>When I have multiple image with the .homeimage class, and multiple checks to determine the image source, will it make all of the images in the .homeimage class that src at the end? So whatever the last image that gets checked is the image src for all of the images with the ".homeimage" class? I don't want that. How can I uniquely make each image? Make a custom id instead of a class for each div? Also, does this script have to be below the html in question? Or does that not matter</p>

<p>Thanks for the future advice you all.</p>