How do I call an onclick function within document.write?
<p>I have the following line of code in my Javascript file which I would like to call the function <code>hide</code> when the user clicks on the link test however it does not appear as a link on the page. What do </p>

<pre><code>document.write('&lt;a href="#" onclick="hide();&gt;test&lt;/a&gt;"');
</code></pre>

<p><strong>EDIT 0</strong></p>

<p>Based on the suggestions, the only reason I am using document.write is because I am attempting to display HTML over another page i.e. a takeover page. Would appreciate a better way of doing this. The intention is until the user clicks on "test" the preceding HTML would be displayed. When they click on test, the preceding HTML is hidden and the page content as it would normally display is shown.</p>

<pre><code>function show() {
    obj1 = document.getElementById("container");
    obj1.style.position = "absolute";
    obj1.style.top = "0px";
    obj1.style.left = "0px";
    obj1.style.width = "100%";          
    obj1.style.textAlign = "center";
    obj1.style.zIndex = "9999";
    obj1.style.visibility = "visible";
    obj1.style.display = "inline";
    obj1.style.backgroundColor = "#FFF";
    document.write('&lt;h1&gt;Hello World!&lt;/h1&gt;&lt;p&gt;Have a nice day!&lt;/p&gt;');
    document.write('&lt;a href="#" onclick="hide();"&gt;test&lt;/a&gt;');

}

function hide() {   
    obj1 = document.getElementById("container");
    obj1.style.display = "none";
    obj1.style.visibility = "hidden";
}
</code></pre>

<p><strong>Full Code</strong></p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict/EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtm1-strict.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset="UTF-8" /&gt;
    &lt;meta http-equiv="content-language" content="en-us" /&gt;
    &lt;meta name="keywords" content="" /&gt;
    &lt;meta name="description" content="" /&gt;
    &lt;meta name="author" content="" /&gt;
    &lt;meta name="copyright" content="&amp;copy; 2012" /&gt;

    &lt;title&gt;takeover&lt;/title&gt;

    &lt;base href="" /&gt;
    &lt;link rel="stylesheet" href="" /&gt;

    &lt;style type="text/css" media="all" /&gt;

    #container {
         position:absolute;
         text-align:center;
         background-color:#fff;

         z-index:10;
    }

    &lt;/style&gt;

    &lt;script type="text/javascript" src="takeover.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div&gt;
        &lt;div id="container"&gt;abc&lt;/div&gt;
        &lt;p&gt;&lt;a href="#"&gt;test&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;

&lt;script type="text/javascript"&gt;
     window.onload = show;
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>EDIT 1</strong></p>

<p>Okay, having scoured a multitude of forums it appears that document.write replaces the entire screen and hence the inability to call the appropriate div element. I have instead replaced the javascript above with the below however am unsure where it is the proper way of doing it.</p>

<pre><code>function show() {
    obj1 = document.getElementById("container").innerHTML ='&lt;p&gt;Hello World.&lt;br&gt;Here I am.&lt;/p&gt;';
    obj1 = document.getElementById("container").innerHTML +='&lt;a href="#" onclick="hide();"&gt;test&lt;/a&gt;';

}

function hide() {   
    obj1 = document.getElementById("container");
     if(obj1)
 {
   alert("Going to hide the element");
   obj1.style.display = "none";
   obj1.style.visibility = "hidden";
 }
 else
 {
   alert("Cannot find the element with id container.");
 }
}
</code></pre>
