jquery - Migrating from .live to .on when using functions and selector -
probably simple answer don't understand principles of jquery enough work out.
i have this:
$(".remove", document.getelementbyid(itemsareaid)).live("click", function(){
which want migrate .on()
i tried doing this
var selectedels = $(".remove", document.getelementbyid(itemsareaid)); $(document).on('click',selectedels, function(e){
but doesn't work.
anyone explain i'm doing wrong?
and if possible why solution didn't work can understand.
many thanks,
paul
the optional selector on()
must string. you're providing jquery object (selectedels
).
instead, use string selector .remove
directly. rather targeting document
, use itemsareaid
;
$('#' + itemsareaid).on('click', '.remove', function ());
if wanted target document
, use descendant selector along itemsareaid
, .remove
, this;
$(document).on('click', '#' + itemsareaid + ' .remove', function ());
... it's better attach handlers close source possible, first preferred.
Comments
Post a Comment