Skip to content

Instantly share code, notes, and snippets.

@jgonggrijp
Created May 13, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgonggrijp/1b581f19a79913d94aba to your computer and use it in GitHub Desktop.
Save jgonggrijp/1b581f19a79913d94aba to your computer and use it in GitHub Desktop.
parent node error with jQuery Mobile and jQuery.prototype.clone()
I have a multipage document that includes, among others, a page like the following:
<div id="original" data-role="page">
<form class="problematic" onsubmit="diagnostic();"></form>
</div>
At the bottom of the HTML (end of body) I have a script that clones this page, like this:
$('#original').clone().attr('id', 'copy').appendTo(document.body).page();
When I submit the copy of the form in the cloned page, the error is revealed in the submit handler with code like this:
function diagnostic(event) {
console.log($(event.target).parent()); // prints $('#original') instead of $('#copy')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment