2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JSXを使わずにJS内にHTMLを記述する

Last updated at Posted at 2019-11-15

結論

IE以外はテンプレートリテラル
IEは無名関数 + コメントアウト
を使用する

※htsignさんにコメント頂いた内容を更新しました。ありがとうございます。

IE以外(ES6対応ブラウザ)

getHtmlTemplete.js
let insert_html = `
 <div class="greeting">
   Hello World!
 </div>
`;

document.getElementById("insert_target").innerHTML = insert_html;

IE

getHtmlTemplete.js
var insert_html = function(){/*
 <div class="greeting">
   Hello World!
 </div>
*/}).toString().match(/\/\*([^]*)\*\//)[1];

document.getElementById("insert_target").innerHTML = insert_html;

2
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?