I have a div with id="div_register". I want to set its width dynamically in JavaScript.
I am using this following code:
getElementById('div_register').style.width=500; but this line of code isn't working.
I also tried using the units px like the following, still no luck:
getElementById('div_register').style.width='500px'; and
getElementById('div_register').style.width='500'; and
getElementById('div_register').style.width=500px; but none of this code is working for me.
I don't know what's going wrong.
I am using Mozilla Firefox.
EDIT
<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>
onloadevent has occured?div_registeris the right id of your element? Maybe give us some html, too...style.width="500px";should be right.onclick="show_update_profile()"instead ofonclick="javascript:show_update_profile()"