The details/summary should be built as a string then insert it after $elm. No need for all the jQuery object creation, appendTo or .html().