开发者

Intercepting Hyperlink Clicks After jQuery .load()

开发者 https://www.devze.com 2023-02-27 01:33 出处:网络
What\'s the technique to intercept hyperlink clicks after they are loaded via a jQuery .load()? I have a jQuery .load() that\'开发者_运维知识库s pulling back some hyperlinks that act as \"buttons\",

What's the technique to intercept hyperlink clicks after they are loaded via a jQuery .load()?

I have a jQuery .load() that'开发者_运维知识库s pulling back some hyperlinks that act as "buttons", which look like this:

<a class="button" href="" onclick="install('test1');return false;">Install Test1</a>
<a class="button" href="" onclick="install('test2');return false;">Install Test2</a>

The trouble I'm having is that the href is firing instead of the onclick handler.

Of course, I tried doing this differently with jQuery's live() function on the 'click' event, but the href is firing instead.


"Of course, I tried doing this differently with jQuery's live() function on the 'click' event, but the href is firing instead." - well that is the way it should be done, and it's proven to work, so I guess

  • you do not execute the live bindings from your document ready
  • your selector for the bindings is not correct
  • you don't return false from your live() function, so event delegation continues

Any of the above would result in 'firing' the hrefs.

0

精彩评论

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

关注公众号