开发者

distinguish between events original and cloned html block

开发者 https://www.devze.com 2023-01-07 10:25 出处:网络
I am using jquery 1.3 , When i clone the element with clone(true) all the data + event are copied , but the problem is

I am using jquery 1.3 ,

When i clone the element with clone(true) all the data + event are copied , but the problem is to distinguish between event of the original html block and cloned html block.

When i tries to fire event to cloned html blocks then original html block's event also get fired.

so now the big problem is how to distinguish between events

checkout th开发者_如何学JAVAe code over here jsfiddle.net/BbBqJ/1


When you have a selector like $('.edit') for example, you are selecting all of that element on the page.

To focus the selector to a limited context, you can pass a second argument. So what I did was to store the new element you created into a variable called $box, and then passed that in as the context like $('.edit', $box).

I made other changes to your code to clean things up too.

http://jsfiddle.net/sxkxp/1/

Again, just remember that a selector like .edit is affecting all those elements that exist on the page.


Use the event target and it should only interact with the origin of the event...

$("something").bind("click", function (event) {
   $(event.target).css("border", "1px solid #f00");
});
0

精彩评论

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

关注公众号