views:

102

answers:

1

Hi, In my web app, I am using jQuery to select all the links on the page and intercept where they go to so that I can switch to a different part of the page with AJAX. The problem is that some of these links are in InfoWindows (if that's what they're called) on a Google Map. For some reason the jQuery selector $('a') isn't selecting them. They're loaded at the same time that the page is (which is when $('a').click is called) and I don't see how they don't show up in the DOM. Any ideas?

A: 

I think that the content of the infoWindows is injected to the DOM programmatically, when the window is shown up, so the links are not present when you execute your selector.

Try to bind the click event with live:

$('a').live('click', function () {
  // ..
});

The live method works with event delegation, and it will work for all the anchors present in the document.

CMS
FYI info window content is loaded into the DOM when the developer specifies an html string as the content (most likely what is happening here). However the api first and foremost supports setting the info window content as a DOM node, in which case it can exist in the DOM whenever the developer chooses, and having whatever events bound to it already. http://code.google.com/apis/maps/documentation/reference.html#GMap2.openInfoWindow
Crescent Fresh