Search code examples
jqueryclone

jQuery clone with a simple line break


<select id="things">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

$('#things').after($('#things').clone());

How could I insert a break between these two elements while cloning? Is there a neat way to do it in one line of code? I have tried:

$('#things').after('<br/>' + $('#things').clone()); //returns [object object]

http://jsfiddle.net/ydAdS/


Solution

  • You're trying to add a string, and an object. Create a jQuery object for the <br/> instead:

    $("#things").after( $("<br>").add( $("#things").clone() ) );​​​​​​​​​​
    

    Fiddle: http://jsfiddle.net/As2Se/