I have few div HTML elements and i am cloning it with a clone(true) option as i want to copy the events also.
Now the case there are certain click events in my HTML div blocks and while crating events i use context parameter also like
var $block ="<div class='task-create-content' >"+
"<div class='task-create-preview'>"+
"<div class='items'>" +
"<div><input type='text' class='edit wtp'/></div>" +
"<div><input type='text' class='edit wtp'/></div>" +
"</div>"+
"</div>");
$(".wtp", $block).live('click',function() {
alert("hi");
})
Now , when i clone this block using clone(true), click event doesn’t get fire even if i am assigning context parameter.
The
.live()method needs the actual selector to match the element against.Try this:
It uses that selector at the root of the document to see what exactly received the click event. If there’s a match, it fires the handler for that selector.
It seems as though you’re assigning handlers directly for newly created elements. If you want to do that, use
.bind().…which is the same as doing:
EDIT:
The correctA couple of ways to confine alive()event to$blockwould be to pass$blockas a third argument tolive().…which is the same as using
.delegate()jQuery’s
.delegate()just nicer packaging for passing the third argument to.live(). It just reorders the arguments, and calls.live().http://github.com/jquery/jquery/blob/master/src/event.js#L875