最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Combine two html selections with jquery - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

5 Answers 5

Reset to default 11

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));

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');
发布评论

评论列表(0)

  1. 暂无评论