javascriptjqueryrubygoogle-mapseruby

Google Maps listener only firing once?


Hello so basically what I wanted was so when you clicked a marker, it fired of some jQuery that would replace a div's contents. Works perfectly the first time, but afterwards it won't respond. Any suggestions? Thanks!

 google.maps.event.addListener(marker, 'click', function() {
    $('.address').replaceWith(" + '"' + $arrayOfEventNames[i] + '"' + ");

Note: This is using embedded ruby code to get the "event name" I want. So this is inside a puts statement. hence the need of the quotes.


Solution

  • You do not replace the content of $('.adress') but the element itself. That means that after first click it does not exist anymore so cannot be replaced.

    K