开发者

Multiple click events

开发者 https://www.devze.com 2022-12-28 10:13 出处:网络
I have some popup dialogs 开发者_如何学运维on my webpage, in each of these dialogs I have defined some click event with jQuery :

I have some popup dialogs 开发者_如何学运维on my webpage, in each of these dialogs I have defined some click event with jQuery :

 $(".links_view").click(function(e){     //code     });

But the problem is when I activate one this click event, it will be executed in each dialog...


$(".links_view").click(function(e){  e.preventDefault()   });

also have your dialogs different class OR id!?


I believe you want to isolate your click attachment; to do this, just make your selector (currently ".links_view") more specific.

For example, if you have the following HTML

<div id="one">
  <button class="links_view">Hi</button>
</div>
<div id="two">
  <button class="links_view">Ho</button>
</div>

the code $('.links_view') will grab both, but you can use $('#one .links_view') to just get the first or $('#two .links_view') for the second.

Here's a good tutorial on selectors: http://reference.sitepoint.com/css/selectorref

0

精彩评论

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