开发者

Selecting Links in Google Maps InfoWindows w/ jQuery

开发者 https://www.devze.com 2022-12-12 18:06 出处:网络
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 s

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消