Array alerts 0 for .length not sure why
<p>I'm pretty new to JQuery, I'm trying to make an event so when table row is clicked it does something, but it will have a <code>for</code> loop, but that wasn't working so I removed the loop and did an alert to see how many items were inside of the array, it alerts 0. I'm not sure why, on page load the script generates markers from my database and loads them onto the map (That works fine and as intended) on the left side of the screen a table is made that says what street each stop is on, and when you click on the table row it is supposed to center and zoom on the marker (I can figure that part out on my own) But right now it's telling me there is nothing in the array and I'm not sure why. Thanks.</p>

<pre><code>  &lt;?php
require_once('config.inc.php');
require_once($rootdir . $dirsubfolder . 'navbar.php');
include($rootdir . $dirsubfolder . 'php/findmarkers.php');
?&gt;
&lt;script&gt;

$(document).ready(function() {
var arrMarkers = [];
var zoom = 6;
var initialLocation;
var map;
var markersArray = new Array();

$("table#listOfStops").find('tr').each(function() {
  $(this).on('click', function() {

      alert(arrMarkers.length);


  });
});

$(window).resize(function () {
    var h = $(window).height(),
        offsetTop = 230; // Calculate the top offset
    $('#gmaps').css('height', (h - offsetTop));
  }).resize();
  loadScript();
});
function initialize() {
  geocode = new google.maps.Geocoder();
 var mapOptions = {
  zoom: 10,
  center: new google.maps.LatLng(56.7626362, -111.379652),
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  disableDefaultUI: false,
  zoomControl: true,
  zoomControlOptions: {
    style: google.maps.ZoomControlStyle.LARGE
  }
};

  map = new google.maps.Map(document.getElementById('gmaps'),
  mapOptions);

  google.maps.event.addListener(map, 'click', function(event) {
    var latitude = event.latLng.lat();
    var longitude = event.latLng.lng();
    deleteOverlays();
    addMarker(event.latLng);
    updateTextFields(latitude, longitude);
  });
  &lt;?php while($stmt -&gt; fetch()) { ?&gt;
  var long = "&lt;?php echo $gLongitude ?&gt;";
  var lati = "&lt;?php echo $gLatitude; ?&gt;";
  var title = "&lt;?php echo $gTitle; ?&gt;"
  setMarker(lati, long, title);
  &lt;? } $stmt -&gt; close(); $mysqli -&gt; close();?&gt;



}

function setMarker(lat,lon, markerTitle) {
  var latLonMarker = new google.maps.LatLng(lat,lon);
  marker = new google.maps.Marker({
    position: latLonMarker,
    map: map,
    icon: 'icon.png',
    title: markerTitle
  });
  google.maps.event.addListener(marker, 'dragend', function() {
    $('#inputLatitude').val(this.getPosition().lat());
    $('#inputLongitude').val(this.getPosition().lng());
  });
  arrMarkers.push(marker);
}


function loadScript() {
  var script = document.createElement('script');
  script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=true&amp;' +
  'callback=initialize';
  document.body.appendChild(script);
}
&lt;/script&gt;

&lt;?php include($rootdir . $dirsubfolder . 'php/findmarkers.php'); ?&gt;

&lt;div style="padding-top: 5%; padding-bottom: 5%;"&gt;
&lt;div class="container-fluid"&gt;
&lt;div class="row-fluid"&gt;
  &lt;div class="span3 container hero-unit"&gt;
  &lt;h2 style="text-align: center;"&gt;Route &lt;?php echo $gRouteNumber ?&gt;&lt;/h2&gt;
  &lt;h4 style="text-align: center;" class="alert-info"&gt;Begins &lt;? echo $gArrivalTime; ?&gt;&lt;/h4&gt;
  &lt;br /&gt;

  &lt;table id="listOfStops" class="table table-striped"&gt;
  &lt;thead&gt;
  &lt;tr&gt;
    &lt;th&gt;Stop #&lt;/th&gt;
    &lt;th&gt;Street Name&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
  &lt;?php
  $i = 0;
  while($stmt -&gt; fetch()) {
    echo '&lt;tr  id="' . $i . '"&gt;';
    echo '&lt;td&gt;' . $gStopNumber . '&lt;/td&gt;';
    echo '&lt;td&gt;' . $gStreetName . '&lt;/td&gt;';
    echo '&lt;/tr&gt;';
  $i++;} $stmt -&gt; close(); $mysqli -&gt; close(); ?&gt;  
  &lt;/tbody&gt;
  &lt;/table&gt;




  &lt;/div&gt;

&lt;div class="span9"&gt;
&lt;div id="gmaps"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;




&lt;?php
require_once('footer.php');
?&gt;
</code></pre>
