Reputation: 49
I have a problem that can not solve.
This code works perfect for me.
// click row opens message, unless you click delete
$('.delete_message-link-js').live('click', function(e) {
e.preventDefault();
});
$('.item-message').live('click', function(e){ //.item-message - tr lass
window.location = $(this).find(".show_message-link").attr("href");
});
But when i change .live() to .on()
// click row opens message, unless you click delete
$('.delete_message-link-js').on('click', false );
$('.item-message').on('click', function(e){
window.location = $(this).find(".show_message-link").attr("href");
});
i have a bug in Firefox . When I click at .delete_message-link-js link in table row i get a error
prompt aborted by user
throw Components.Exception...by user", Cr.NS_ERROR_NOT_AVAILABLE);
But code works in Safari.
What i doing wrong?
Thanks and sorry for my english
Upvotes: 4
Views: 820
Reputation: 140220
Read the documentation:
From there we can see that the on
equivalent of this:
$('.delete_message-link-js').live('click', function(e) {
e.preventDefault();
});
is:
$( document ).on( "click", ".delete_message-link-js", function(e){
e.preventDefault();
});
And so on.
You could also read the source code to see how live
is transformed into on
:
live: function( types, data, fn ) {
jQuery( this.context ).on( types, this.selector, data, fn );
return this;
}
this.context
is document
(the default context as you did not give any context) and this.selector
is '.delete_message-link-js'
for the above example.
Upvotes: 9
Reputation: 32716
You need to attach the .on()
to the parent of the item:
// Pseudocode...
$('#parent of .delete_message-link-js').on('click', '.delete_message-link-js', false );
Upvotes: 0