Note that there are some explanatory texts on larger screens.

plurals
  1. POdocument.getElementById() is getting Null
    text
    copied!<pre><code>function createDiv(nameId,width,height,color) { try { // Initialize And Create Div if(document.createElement('div')) { // document.write("&lt;br&gt;Create Div Success"); if((nameId.length!=0) &amp;&amp; (width&gt;0) &amp;&amp;(height&gt;0) &amp;&amp; (color.length!=0)) { //creating div var divCreate = document.createElement('div'); divCreate.id=nameId; document.getElementById(nameId).width = width; document.getElementById(nameId).height = height; document.getElementById(nameId).background = color; document.getElementById(nameId).backgroundColor = "Red"; document.body.appendChild(divCreate); document.write(" &lt;br&gt;Create Div Success And Added To Body"); // document.write(" &lt;br&gt;Create Div Success And Added To Body"); } else { // document.write("&lt;br&gt;All Field Value Required"); } } else { document.write("&lt;br&gt;Unable To Create Div"); } } catch(e) { document.write("&lt;br&gt;"+e); } } </code></pre> <p><code>document.getElementById()</code> is getting <code>Null</code>. I am trying to create a DIV using javascript and assigning some width/height and color to it, but its not working. However, if I use the code below the div gets created but it's not visible on the screen. And if I use the function <code>createDiv()</code> it does not work.</p> <pre><code>divCreate.id=nameId; divCreate.width = width; divCreate.height = height; divCreate.background = color; divCreate.backgroundColor = "Red"; document.body.appendChild(divCreate); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload