I am trying to clone an HTML5 element using jQuery 1.8.1, but this jsbin example fails in IE <9 (element not cloned)
Code (Simplified)
<head> <script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> </head> <body> <section>My section</section> <button>Clone section</button> ... <script> var section = $('section'); $('button').on('click', function() { var clone = section.clone(true); $(clone).insertAfter($('section:last')); }); $('section').on('click', function() { alert('hey, I am a section'); }); </script> </body>
This, of course, is a simplified demonstration. In my real code, I have many nested elements with several events:
My questions
So far, the only workaround I have found is to copy all nodes via html() , add them via append() and refactor my code using event delegation for events related to these nodes, for example
$('body').on('click', 'section', function() { alert('hey, I am a section'); });
But I am open to different ideas: can I use a more elegant / efficient / simpler / faster approach?
Thanks.
source share