Ho un div
con id="div_register"
. Voglio impostarlo width
dinamicamente in JavaScript.
Sto usando questo codice seguente:
getElementById('div_register').style.width=500;
ma questa riga di codice non funziona.
Ho anche provato a utilizzare le unità px
come le seguenti, ancora senza fortuna:
getElementById('div_register').style.width='500px';
e
getElementById('div_register').style.width='500';
e
getElementById('div_register').style.width=500px;
ma nessuno di questo codice funziona per me.
Non so cosa stia andando storto.
Sto usando Mozilla Firefox.
MODIFICARE
<html>
<head>
<title>Untitled</title>
<script>
function show_update_profile() {
document.getElementById('black_fade').style.display='block';
//document.getElementById.('div_register').style.left=((window.innerWidth)-500)/20;
document.getElementById('div_register').style.height= "500px";
document.getElementById('div_register').style.width= '500px';
//alert('kutta');
document.getElementById('div_register').style.display='block';
document.getElementById('register_flag').value= 1;
document.getElementById('physical_flag').value= 0;
document.getElementById('cultural_flag').value= 0;
document.getElementById('professional_flag').value= 0;
document.getElementById('lifestyle_flag').value= 0;
document.getElementById('hobby_flag').value= 0;
//alert(window.innerWidth);
}
</script>
<style>
.white_content {
display:none;
}
</style>
</head>
<body>
<div id="main">
<input type="button" onclick="javascript:show_update_profile();" id="show" name="show" value="show"/>
</div>
<div id="div_register">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
welcome
</td>
</tr>
</table>
</div>
</body>
</html>
div_register
è l'ID corretto del tuo elemento? Forse dacci anche dell'html ... style.width="500px";
dovrebbe essere giusto.
onclick="show_update_profile()"
posto dionclick="javascript:show_update_profile()"
onload
si è verificato l' evento?