title: Google maps infoWindow - destroys content on close?
body: <p>I am using google maps on my site. I have an infoWindow that I populate with content like this:</p>
  
  <pre><code>infowindow = new google.maps.InfoWindow({ content: $('infoWindowContent') });
  
  google.maps.event.addListener(mapMarker, 'click', function() {
      $('infoWindowContent').setStyle('display','block');
  
      $('iw_companyName').innerHTML = "stuff";
      $('iw_recommends').innerHTML = "stuff";
      $('iw_activity').innerHTML = "stuff";
  
      infowindow.open(googleMap,item);
  </code></pre>
  
  <p>});</p>
  
  <p><code>$('infoWindowContent')</code> is an element of my page that I create in the html:</p>
  
  <pre><code>&lt;div id="mapholder" class="box"&gt;
      &lt;div id="infoWindowContent" style="display:none;"&gt;
          &lt;div class="center"&gt;
              &lt;h4&gt;&lt;a id="iw_companyName"&gt;&lt;/a&gt;&lt;/h4&gt;
              &lt;div&gt;Activity: &lt;a id="iw_activity"&gt;&lt;/a&gt;&lt;/div&gt;
              &lt;div id="iw_recommends"&gt;&lt;/div&gt;
          &lt;/div&gt;                        
      &lt;/div&gt;                
      &lt;div id="map_canvas"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So when the page is created, the content is invisible. When the user clicks a marker, the infoWindow appears there, and the content is populated with appropriate values. If the user clicks another marker, the infoWindow moves, and has its values changed.</p>
  
  <p>The problem is when the user clicks the 'x' button on the top of the info window to close it. The close functionality works fine, but when the user clicks a marker again, I get the following error:</p>
  
  <pre><code>$("infoWindowContent") is null
  [Break On This Error] $('infoWindowContent').setStyle('display','block');
  </code></pre>
  
  <p>So, <code>$('infoWindowContent')</code> was destroyed when the infoWindow was closed.</p>
  
  <p>How do I get around this? I don't really want to construct a new infoWindowContent in the javascript each time the user clicks a marker, as it is much harder to read/understand/change html generated in this fashion. Or is my way of approaching a solution here flawed?</p>