javascript - JQuery delegated events work like direct events -
I add a dynamic button to my page and I want to make an AJAX request when I click on it.
But my code handles the click of every document, what am I doing wrong?
& lt; Script type = "text / javascript" & gt; Var $ selButton = $ ("Input [id = = btn_match_]"); $ (Document) .on ("click", $ sel button, function (e) {// executed on every click on the code page and not only on button clicks}); & Lt; / Script & gt; One of my buttons:
& lt; Input id = "btn_match_26179" class = "btn btn-primary btn-x" type = "submit" & gt;
The selector is considered a string, not a jQuery object. If this is not a string, instead of acting as a selector, the handler will be passed as a event.data . See. Try this:
var selector = "input [id = = btn_match_]"; $ (Document) .on ("click", selector, function (e) {// ...});
Comments
Post a Comment