Subscribe

Recent Articles

Creating and submitting forms with jQuery in Firefox

There’s an interesting gotcha when creating and submitting forms using jQuery in Firefox. Firefox silently fails to submit forms that have not yet been attached to the DOM. For example, consider the following scenario:

Clicking on a link with CSS class “destroy” in Safari or Chrome works as expected — a form is created and submitted. In Firefox, nothing seems to happen. To get it working in Firefox, the form must be attached to the DOM, e.g., using appendTo():

With the addition of f.appendTo($('body')), clicking on a link with CSS class “destroy” submits in Firefox (as well as Safari and Chrome). I scratched my head on this for a while before stumbling across balpha’s comment on the jQuery API documentation for submit().

blog comments powered by Disqus