开发者

Using delegate() for dynamically added container

开发者 https://www.devze.com 2023-04-07 00:17 出处:网络
Could you explain me how I can catch click event for dynamically added checkbox? I can do it, but can\'t understand one thing - why can\'t use delegate() for dynamically added container for checkbox.

Could you explain me how I can catch click event for dynamically added checkbox? I can do it, but can't understand one thing - why can't use delegate() for dynamically added container for checkbox. Code is like that:

<p sty开发者_运维技巧le="blue">
<input type="checkbox" name="first" />
</p>

Example here.

In this example I never catch the message ".blue CLICK" but only see "#ch CLICK".


In your example - When the delegate is initialised the p element with the blue class does not exist. The container you setup the delegate on needs to exist in the dom.

0

精彩评论

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