Reputation: 495
I'm trying to click a rails ajax link using jquery by clicking on a google map marker but can't figure out how to do it. Here's the link :
sidelistings div
<% @properties.each_with_index do |property,index| %>
<div class="sidelisting" id="<%= index %>">
<div><%= link_to image_tag("http://432.mlsimages.movoto.com/0#{property.mls.last(2)}/tn/#{property.mls}_0.jpg"), {:action => 'show', :id => property.id}, :remote => true %> </div>
I have a google map with 20 markers on it which match the 20 properties in the above sidelistings
div. I want to be able to click on the map marker and that will click the above link for it's corresponding property. I have made the id
s of the 20 sidelistings match the indexes of the array of map markers. Here's my attempt at the jquery in the google maps code:
google.maps.event.addListener(markerArray[i], 'click', function(){
var element = this.id;
var sidelisting = document.getElementById(element);
$('sidelisting:a').click();
});
The above code doesn't throw any errors in the console but clicking on the map marker does nothing, what am I doing wrong?
Upvotes: 0
Views: 524
Reputation: 495
Got it figured out, I was getting a couple of things wrong, here's the working code:
google.maps.event.addListener(markerArray[i], 'click', function(){
var index = markerArray.indexOf(this);
$('#' + index + ' a').click();
});
I didn't know I had to construct the selector within the $()
that way with the plus signs and the space before the a tag is also required
Upvotes: 1