div
要素を手動で作成し、後で JavaScript を使用して CSS スタイルを追加したいと考えています。要素を作成し、そのdiv
スタイルを JavaScript で変更しました。問題は、一部の CSS スタイルが機能しないことです。
( color
、background
、) これらのプロパティは正常に機能しましたが、 ( width
、、)プロパティは機能しません。これがなぜ起こるのか、そしてそれを修正する方法を知りたいです。height
zIndex
top
left
これは私のJavaScriptコードです:
function css()
{
var element = document.createElement('div');
element.id = "someID";
document.body.appendChild(element);
element.appendChild(document.createTextNode
('hello this javascript works'));
// these properties work
document.getElementById('someID').style.zIndex='3';
document.getElementById('someID').style.color='rgb(255,255,0)';
document.getElementById('someID').style.background='rgb(0,102,153)';
document.getElementById('someID').style.width='700px';
document.getElementById('someID').style.height='200px';
//these do not work
document.getElementById('someID').style.left='500px';
document.getElementById('someID').style.top='90px';
}
これは私の関連するhtmlコードです
<input type="submit" name="cssandcreate" id="cssandcreate" value="css" onclick="css();"/>