jQuery Print elements pushed into array -
i have following code:
var $element1 = $('#selector'), $element2...; var $elements = [ $element1, $element2, $element3 ], $classes = ['class1','class2','class3'], $newelements = []; $.each($elements, function($i, $element){ $newelements.push('<li class="'+ $classes[$i]+'">' + $element +'</li>'); }); $(body).append( $newelements );
the output being:
<li class="class1">[object object]</li> <li class="class2">[object object]</li> <li class="class3">[object object]</li>
how can print actual elements?
use outerhtml
of element being appended:
$.each($elements, function($i, $element){ $newelements.push('<li class="'+ $classes[$i]+'">' + $element[0].outerhtml +'</li>'); });
Comments
Post a Comment