why jquery detach element will cause a form to submit?
Posted
by jiewmeng
on Stack Overflow
See other posts from Stack Overflow
or by jiewmeng
Published on 2010-05-31T15:24:22Z
Indexed on
2010/05/31
15:43 UTC
Read the original article
Hit count: 272
JavaScript
|jQuery
i wonder why in the following example, trying to detach
an element (li
) causes the form
containing it to submit
html
<form id="frmToDo" name="frmToDo">
<p id="lineInput">
...
<input type="submit" id="btnSubmit" value="Add" />
</p>
<ul id="todolist">
<!-- added in ajax -->
</ul>
</form>
JS
$("#frmToDo").submit(function() {
// this runs after: $("#todolist").detach(...)
});
$("#todolist").delegate("li[id^=task-] button", "click", function() {
$("#todolist").detach($($(this).parent()).id());
return false;
});
© Stack Overflow or respective owner