I can attach the onclick event to a function,
$ (". Options "). Click (function () (Alert ($ (this) .val ())})
but with the .options
elements are changed at all times User's Contact How can I set it, whenever I can create the .option
element?
quick answer: use of event delegation
$ (document) .on ('click', '.options', function () {alert ($ (this) .val ());}); More answers: Above, but attach the goal of the delegation to the bottom of the delegation tree, as you may be without the risk of deleting it (or where are you adding alternatives. Near), can be done without just for the document
; Doing this ensures that the delegation does not affect the goal for all clicks on the click event page. $ ('some existing elements'). ('Click', '.' ', Function () {warning ($ (this) .val ());});
Comments
Post a Comment