I am trying to wrap an input element with a div, and then append another element to the wrapping div.
Markup:
<div>
<input type="text" id="foo" />
</div>
JS:
var wrapper = $('<div class="wrapper"></div>'),
somethingElse = $('<div class="something-else"></div>');
$('#foo').wrap(wrapper);
wrapper.append(somethingElse);
JSFiddle: http://jsfiddle.net/ckpeZ/
The problem is the “somethingElse” div is not getting appended to wrapper. It is like the line wrapper.append(somethingElse) is completely ignored. What am I doing wrong?
The wrapper is being cloned, you need to append to the new element that was created.
http://jsfiddle.net/ckpeZ/4/