5

I have the HTML but I want to create it programatically. I know how to do it with JavaScript's .createElement .appendChild methods but it's time consuming. I can't find such a conversion tool online.

Does anyone know if there is a tool, an online tool, to take my HTML snippet and generate the JavaScript required to add that to my document?

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91

1 Answers1

1

You can always use innerHTML to just add whole snippet. Or insertAdjacentHTML() to append or prepend at any point in your document

nedt
  • 332
  • 3
  • 15
  • 1
    Yea, I knew about `innerHTML` but none of the professional scripting I've seen uses it. For some reason they always seem to use `.appendChild` and `.createElement`. This type of conversion tool seems useful to only me apparently...? It's a time sink to write the script to append a large chunk of HTML.... – Ronnie Royston May 16 '18 at 22:32
  • innerHTML is actually quite fast, because you save some function calls and browsers are good in parsing HTML. Even jQuery uses innerHTML in `.html()` if possible and to convert HTML strings to elements. – nedt May 16 '18 at 23:04