JavaScript を使用して新しい HTML ドキュメントを作成したいと考えています。本文に div (表示: インライン) を作成し、そこに ap タグを作成します。次に、p タグ (innerHTML) に文字列 (titleTagString) を入れます。今、知りたいのは、div のオフセット幅です。Chrome コンソールは 0 と表示されます...どこが失敗したのでしょうか? ありがとう!
function titleTagTester(titleTagString) {
//Create new document
newDoc = document.implementation.createHTMLDocument('titleTagTester.html');
//Create var body from document
var body = newDoc.getElementsByTagName('body');
//Create div element with style and add to body of document
newDoc.body.innerHTML += '<div style="width:600px" display="inline" id="divId"></div>';
//Create p element with style and add to div of body of document
newDoc.getElementById('divId').innerHTML += '<p style="color:#1a0dab" "font-family:arial" font-size:18px;">' + titleTagString + '</p>';
//getwidth of div
return newDoc.getElementById("divId").offsetWidth;
}