Skip to content Skip to sidebar Skip to footer

Combine Two Html Selections With Jquery

Is it possible two combine two html selections in jquery? var derp1 = $('#derp1').html(); var derp2 = $('#derp2').html(); var combDerp = derp1.add(derp2); $('#derpina').html(comb

Solution 1:

Since you are getting the html of each, you can just concatenate the two.

$('#derpina').html(derp1 + derp2);

Or, you can take the actual nodes and move them.

var derp1 = $("#derp1");
var derp2 = $("#derp2");

$("#derpina").html(derp1.add(derp2));

Solution 2:

Just change

var combDerp = derp1.add(derp2);

to

var combDerp = derp1 + derp2;

Solution 3:

Just concatenate them.

var combDerp = derp1+derp2;

Solution 4:

Solution 5:

If you want the elements to move, you should just use:

$('#derp1, #derp2').contents().appendTo('#derpina');

If you want to copy them, you should use:

$('#derp1, #derp2').contents().clone().appendTo('#derpina');

Post a Comment for "Combine Two Html Selections With Jquery"