I have the following code
var input = $('#el_id');
wrapper = $(document.createElement('div'));
wrapper.addClass('small');
wrapper.css('width',200);
input.wrap(wrapper);
alert(input.children().length)
I get 0 for the children length. What I want is:
<div class="small" style="width: 200px;">
<input type="text" id="el_id" />
</div>
But I want the small div to be dynamically generated. Any idea why this isn't working?
UPDATE
It turns out my issue lies on another line of code. I want to assign the wrapper to a variable after I wrap and:
block = input.wrap("<div class='"+container_class+"' style='width: "+wrap_width+"px;'></div>");
does not work. It returns the input which makes sense. But how can I return the wrapper?
Thanks!