i have a div element generate in runmode by javascript
I want first click show confirm message and next click remove click event
but die or unbind don’t work!
$('div').live('click',function(e) {
$(this).toggle(function () {
$(this).html("I'm sure!");
return false;
},
function (e) {
$(this).html("Deleting...");
$(this).die('click').die('click');
}).trigger('click');
});
How about that?
EDIT. Example is here: http://jsfiddle.net/93nPA/
EDIT 2.
If you wish the script to add click event to the generated elements automatically, just add the class to the generated element (e.g.
mybutton), and use this code once in the very top of your JavaScript:$("body").on("click", "div.mybutton", function(e) { ... });.