title: Google Maps Dynamically Change Info window
body: <p>Pretty straight forward question about google maps API v3. </p>
  
  <p>I am wanting to change the text on the click event of the a> tag. That works fine but when the infowindow closes and reopens, the text is reset.</p>
  
  <p><strong>Conditions:</strong> There will be multiple markers on the map.</p>
  
  <p><strong>Here is the code where I am defining the marker its actually called in a For Loop (didnt post that):</strong> </p>
  
  <pre><code>contentString = 
      '&lt;div id="infoContent"&gt;' +
      '&lt;div id="siteNotice"&gt;' +
      '&lt;h4 id="firstHeading" class="firstHeading"&gt;Store ' + 
      Store[x].StoreNumber + 
      ' - ' + 
      Store[x].Location + 
      '&lt;/h4&gt;' +
      '&lt;div id="bodyContent"&gt;' +
      '&lt;ul&gt;' +                          
      '&lt;li&gt;&lt;a onclick = "addDispatch(this,' + Store[x].DailyDispatchID +')"&gt; Add &lt;/a&gt;&lt;/li&gt;' +
      '&lt;/ul&gt;' +
      '&lt;/div&gt;&lt;/div&gt;';
  
  
  infowindow = new google.maps.InfoWindow({
      content: contentString
  });
  
  bindInfoWindow(marker, map, infowindow, contentString)
  
  function bindInfoWindow(marker, map, infowindow, strDescription) {            
      google.maps.event.addListener(marker, 'click', function () {
          infowindow.setContent(strDescription);
              infowindow.open(map, marker);
          });
      }
  </code></pre>
  
  <p><strong>As you can see, in the content string, I defined an onclick event that calls 'addDispatch'. The function is here:</strong> </p>
  
  <pre><code>function addDispatch(element, DispatchId) {            
      if (element.text == "Add") {
          $(element).text("Remove");
      } else {
          debugger;
          $(element).text("Add");
      }            
  }
  </code></pre>
  
  <p>It works fine to change the text, but once I re-open the infowindow, it goes back to default. </p>
  
  <p>Anyone have any ideas? </p>
  
  <p>I'm guessing its because the event handler is bound to the content string of the marker window. </p>
  
  <p>I've searched all up and down and can't quite find a solution for this. Thanks in advanced. </p>
  
  <p>(Excuse the debugger code) </p>