div要素を手動で作成し、後で JavaScript を使用して CSS スタイルを追加したいと考えています。要素を作成し、そのdivスタイルを JavaScript で変更しました。問題は、一部の CSS スタイルが機能しないことです。
( color、background、) これらのプロパティは正常に機能しましたが、 ( width、、)プロパティは機能しません。これがなぜ起こるのか、そしてそれを修正する方法を知りたいです。heightzIndextopleft
これは私の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();"/>