戻る

HTMLタグの出力
HTMLタグを出力する方法

HTMLタグの出力サンプル
上記サンプルはdivタグの中にjavascriptで出力したタグが含まれています。
このようにjavascriptで任意のタグを出力できます。

ノードを指定の位置に追加する
[書式]

[第1引数] 位置の指定
beforebeginelementの前に追加
afterbeginelementの子要素の先頭に追加
beforeendelementの子要素の最後に追加
afterendelementの後に追加
[第2引数] 出力文字列
(例)

[insertAdjacentHTML使用例]
getElementByIdで指定したオブジェクトのノードに
指定した位置に出力したい文字列を追加します。
(例)
copy
let element = document.getElementById('xxx');
element.insertAdjacentHTML('beforebegin', '<p>sample</p>');

上記のサンプルを次のように実装しています。
(例)
divタグを準備して
広告のような宣伝タグを表示したい例

[divタグの例]

copy
loadAd();
function loadAd()
{
	const parent = document.getElementById('ad');
	parent.insertAdjacentHTML('afterbegin', ad());
}
function ad()
{
	let path="画像パスを設定します";// ex.) path="img/";
	let fileID="soco-st_sample4.png";
	let text="ソコスト";
	let url="https://soco-st.com";
	let memo="ソコストさんのイラストはこちら";
	let html="";
	html += "<table>";
	html += "<tr>";
	html += "<td>";
	html += "<img src=" + path + fileID + " style='max-width:50px;max-height:50px;'>";
	html += "</td>";
	html += "<td>";
	html += "<label>" + text + "</label>";
	html += "</td>";
	html += "</tr>";
	html += "<tr>";
	html += "<td>";
	html += "[URL]";
	html += "</td>";
	html += "<td style='word-break:break-all'>";
	html += "<a href='" + url + "' TARGET='_blank'>" + text + "</a>";
	html += "</td>";
	html += "</tr>";
	html += "</table>";

	return html;
}

document.write メソッド
現在、HTMLに関する仕様を定めている「HTML Living standard」では、このメソッドの使用について推奨していません。
8.4.3 document.write()
URL [クリックすると開きます])

[謝辞]
「ソコスト」さんの画像を使用させていただいております。
ありがとうございます。
[URL]ソコスト
URL[https://soco-st.com][クリックすると開きます])


戻る
back

Outputting HTML tags
How to output HTML tags

HTML tag output sample
The above sample contains a tag output by javascript inside the div tag.
You can output any tag with javascript like this.

Adds a node at a specified position.
[Syntax]

[First argument] Position specification
beforebeginAdd before element
afterbeginAdd to the beginning of the child elements of element
beforeendAdd to the end of element's children
afterendAdd after element
[2nd argument] Output string
ex.)

[insertAdjacentHTML usage example]
Add the string you want to include to the specified position in the node of the object specified by getElementById.
(Example)
copy
let element = document.getElementById('xxx');
element.insertAdjacentHTML('beforebegin', '<p>sample</p>');

The above sample is implemented as follows.
(Example)
Prepare a div tag
An example of displaying promotional tags like advertisements

[Example of div tag]

copy
loadAd();
function loadAd()
{
	const parent = document.getElementById('ad');
	parent.insertAdjacentHTML('afterbegin', ad());
}
function ad()
{
	let path="Set the image path";// ex.) path="img/";
	let fileID="soco-st_sample4.png";
	let text="soco-st.com";
	let url="https://soco-st.com";
	let memo="Check out soco-st.com's illustrations here";
	let html="";
	html += "<table>";
	html += "<tr>";
	html += "<td>";
	html += "<img src=" + path + fileID + " style='max-width:50px;max-height:50px;'>";
	html += "</td>";
	html += "<td>";
	html += "<label>" + text + "</label>";
	html += "</td>";
	html += "</tr>";
	html += "<tr>";
	html += "<td>";
	html += "[URL]";
	html += "</td>";
	html += "<td style='word-break:break-all'>";
	html += "<a href='" + url + "' TARGET='_blank'>" + text + "</a>";
	html += "</td>";
	html += "</tr>";
	html += "</table>";

	return html;
}

document.write メソッド
Currently, then HTML Living Standard does not recommend using this method.
8.4.3 document.write()
URL [click to open the homepage])

[Acknowledgements]
the images used are from "illustration by soco-st.com"
Thank you very much.
[URL]soco-st.com
URL[https://soco-st.com][click to open the homepage])


back



著作権情報
ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。
ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、
または公開したりすることはできません。
当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、
その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について
一切の責任を負わないものとします。