Home > Net >  turn html into string but keep all html tags javascript
turn html into string but keep all html tags javascript

Time:03-07

I have an array of html. I am trying to run remainderHtml.toString() but result is

[object HTMLLabelElement],[object HTMLLabelElement],[object HTMLLabelElement]

How can I run a toString command (or any other command) and create an html string Exactly like my array? I do not want to remove the tags, or extract any data, just plain want to make this array of html one long connected string...

Here is my array of html from the console.log

(4) [label.p-1.font-weight-bold.bg-primary.ml-2.text-white.rounded-capsule.shadow-none.fs--3, label.p-1.font-weight-bold.bg-primary.ml-2.text-white.rounded-capsule.shadow-none.fs--3, label.p-1.font-weight-bold.bg-primary.ml-2.text-white.rounded-capsule.shadow-none.fs--3, label.p-1.font-weight-bold.bg-primary.ml-2.text-white.rounded-capsule.shadow-none.fs--3]

When I put the above into a variable called remainderHtml and try to run a toString() on it, I get [object HTMLLabelElement],[object HTMLLabelElement],[object HTMLLabelElement]

When I click on the arrow in the console to show the html array I get this below


0: label.p-1.font-weight-bold.bg-primary.ml-2.text-white.rounded-capsule.shadow-none.fs--3
1: label.p-1.font-weight-bold.bg-primary.ml-2.text-white.rounded-capsule.shadow-none.fs--3
2: label.p-1.font-weight-bold.bg-primary.ml-2.text-white.rounded-capsule.shadow-none.fs--3
3: label.p-1.font-weight-bold.bg-primary.ml-2.text-white.rounded-capsule.shadow-none.fs--3
length: 4

CodePudding user response:

You probably want to loop through your array and get the element's outerHTML

var allHTML = "";
remainderHtml.forEach(function (elem) {
  allHTML  = elem.outerHTML;
});
  • Related