jquery toggle() not working with variable
<p>I wan't to be able to "toggle" a div using jquery through a function but it gives me </p>

<p>"Uncaught TypeError: Cannot read property 'defaultView' of undefined"</p>

<p>in the chrome debugger. here is my code</p>

<pre><code>function hide(id){
$(id).toggle();
}
</code></pre>

<p>I have also tried</p>

<pre><code>if (document.getElementById(id).style.display=="none"){
    document.getElementById(id).style.display="block";
}
else if (document.getElementById(id).style.display=="block"){
    document.getElementById(id).style.display="none";
}
console.log(document.getElementById(id));
console.log(id);
return document.getElementById(id).style.display;
</code></pre>

<p>and I get an error that says </p>

<p>"Uncaught TypeError: Cannot read property 'style' of null"</p>

<p>More info:</p>

<p>I call <code>hide()</code> from the HTML, I input the HTML using js</p>

<p>here is the basic code</p>

<pre><code>function inputHtml(id){
 var div = document.createElement("div");
 div.innerHTML = '&lt;div id="'+id+'"&gt;&lt;div onclick="hide('+id+')"&gt;hide&lt;/div&gt;&lt;/div&gt;';
 main.appendChild(div);
}
</code></pre>
