I took an exam earlier this morning and there were loads of javascript questions, i managed to answer them all with the exception of just one. I took home the exam paper and am very interested in finding out how to actually do it.
The question is:
[CODE]“Without using events, delays or moving the layout of the existing code, change both DIV’s so they are not displayed. Use the following code and answer in the marked places”
[CODE]<html>
<head></head>
<body>
<div id=”div1″ style=”border:2px solid red;width=300px;margin:5px;”>
Above the code
</div>
<!– Answer A –>
<script language=”javascript” type=”text/javascript”>
</script>
<!– Answer B –>
<script language=”javascript” type=”text/javascript”>
</script>
<div id=”div2″ style=”border:2px solid blue;width=300px;” >
Below the Code
</div>
</body>
</html>
I added these two lines to the code sections
Answer A: document.getElementById(“div1”).style.display = ‘none’;
Answer B: document.getElementById(“div2”).style.display = ‘none’;
When the code was rendered in a browser div1 had disappeared, but div2 had not, as the javascript code is actually before the HTML code.
Any Ideas?