Is it possible two bine two html selections in jquery?
var derp1 = $('#derp1').html();
var derp2 = $('#derp2').html();
var bDerp = derp1.add(derp2);
$('#derpina').html(bDerp);
I want to show two certain parts of html into one and display them in another section of the page. Any help is well appreciated :)
Is it possible two bine two html selections in jquery?
var derp1 = $('#derp1').html();
var derp2 = $('#derp2').html();
var bDerp = derp1.add(derp2);
$('#derpina').html(bDerp);
I want to show two certain parts of html into one and display them in another section of the page. Any help is well appreciated :)
Share Improve this question asked Nov 13, 2012 at 21:37 gardarvalurgardarvalur 1,5859 gold badges40 silver badges67 bronze badges5 Answers
Reset to default 11Since 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));
Just change
var bDerp = derp1.add(derp2);
to
var bDerp = derp1 + derp2;
Just concatenate them.
var bDerp = derp1+derp2;
You can also use JQuery .Append() if you are trying to append HTML.
http://api.jquery./append/
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');