jQuery: array of elements to raw html?
16,569
Nothing automatic, but you could easily do what you just described.
Try it out: http://jsfiddle.net/Y5x5z/
var content = [ $('<p>...</p>'), $('<p>...</p>') ];
var container = $('<div/>');
$.each(content, function(i,val) {
container.append(val);
});
alert(container.html());
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on June 04, 2022Comments
-
Admin about 2 years
Let's say I have an array like this:
var content = [ $('<p>...</p>'), $('<p>...</p>') ];
I need to get the markup of the concatenated elements. So I need to convert
content
" into a raw string: "<p>...</p><p>...</p>
".How can this easily be done? Seems like there should already be something in the framework to do this.
Somehow maybe convert
content
into a document fragment and call.html()
on the document fragment to get the markup? -
Admin about 11 yearsDid you actually try running this bro? 'cause it don't work.
-
aknosis about 11 years@g33kz0r I guess you are right - updated it. The solution is not ideal but it does now work.
-
Roman almost 9 yearsTry
$.fn.append.apply($('<div>'), content).html()