Keep in mind that your jQuery object is still referencing a new one <span>, so if you try to insert it using the chain method, <div>it will not be inserted.
To overcome this, you must first go to the new parent element <div>.
$('<span/>').addClass(spanClass).wrap($('<div/>').addClass(divClass))
.parent().appendTo('body');
You can also write it like this:
$('<span/>').addClass(spanClass).wrap('<div/>')
.parent().addClass(divClass).appendTo('body');
source
share