Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery clone with a simple line break

Tags:

jquery

clone

<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/

like image 683
Norse Avatar asked Dec 06 '25 07:12

Norse


1 Answers

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/

like image 69
Sampson Avatar answered Dec 10 '25 19:12

Sampson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!