-1

Can I convert a string to HTML in javascript?

let description = "<a className="peoplelink" id="ether">Ether</a> // is render as 'the historian of the'";

     let html= // I know that it is easy to do with jquery by using .html() method, but can we convert a string to HTML in javascript?
Harsh Patel
  • 6,334
  • 10
  • 40
  • 73
Gourav Kumar
  • 11
  • 1
  • 3

1 Answers1

3

Nothing to convert, is a simple string to innerHtml:

I.E.:

const markup = `
 <div class="person">
    <h2>
        ${person.name}
    </h2>
    <p class="location">${person.location}</p>
    <p class="bio">${person.bio}</p>
 </div>
`;

document.body.innerHTML = markup;
Mosè Raguzzini
  • 15,399
  • 1
  • 31
  • 43