Skip to content

Instantly share code, notes, and snippets.

@drakakisgeo
Created July 10, 2014 09:10
Show Gist options
  • Save drakakisgeo/d22a569feae0746baebe to your computer and use it in GitHub Desktop.
Save drakakisgeo/d22a569feae0746baebe to your computer and use it in GitHub Desktop.
On click Confirm popup (Jquery)
// Info: Attach event to all elements with this data attribute
// works even for elements that will be created afterwards by Ajax or Jquery
// Only thing you do is to put a data-popmsg attribute in the element you want to click and the value of this attribute
// will be the body of the popup.
$(document).on("click","*[data-popmsg]",function(e){
var msg = $(this).attr("data-popmsg");
if(!confirm(msg))
{
e.preventDefault();
}
});
@drakakisgeo
Copy link
Author

Asterisk(*) is a bit expensive. If you have certain selectors use something more specific to gain some speed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment