jQuery stop click event from bubbling when using $.get() -
I've assigned a click event to a button, which gets a different HTML snippet and uses it to create a div Injects into the element. Html (string) method
$ ('# btnclose'). Click (function () {$ .get ('content' html ', function (data) {$ (' # editcategory '). Html (data);});});
Content.html page is as follows:
& gt; Button ID = "BTN Newcat" type = "button" & gt; Add new category & lt; / Button & gt; & Lt; Script type = "text / javascript" & gt; Click on $ ('# btnNewCategory') (warning ('test')). & Lt; / Script & gt;
Every time I click on the '#btnClose' button, HTML sniper content is displayed but the warning ('Test') is also removed. I have tried the Stopprogram (), Stop Default () and False Return; There is no happiness and there is no happiness. Am I doing wrong, can any light enter ???
Your handler should be like this instead:
$ ('# BtnNewCategory'). Click (function () {warning ('test')});
What is currently firing you alert ('test')
immediately and try to assign the result to a click handler If you want to run when clicking on it, use an anonymous function such as I am above.
This is not a promotional issue, but the binding is one :)
Comments
Post a Comment