Link to home
Start Free TrialLog in
Avatar of MortenWB
MortenWBFlag for Denmark

asked on

trouble hiding DIV tag with javascript

Hi Experts,

For some reason I can't get my code to put a DIV-tag into display=none - mode. I have other similar snippets to work fine, but fail to locate my error.

Any suggestions?
function noticeclose(){
document.getElementById('notice').style.display = 'none';
}

    	<div id="notice" class="examdiv" style="display:block;">

        <font size="+1">Kære musikstuderende.<br>Vis hensyn til hinanden, når i reserverer og følg de gældende retningslinier:<br>
        reserver max 2 timer pr. dag.<br><br>
        Vi har i eksamensperioden også åbnet for, at i kan reservere auditorierne A B og C.<br><br>
        Mvh. administrationen.</font>
        <div style="width:500px; text-align:right;">

        <input name="close" type="button" value="OK" align="right" onclick="noticeclose()" /></div>

    	</div>

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

how many objetc do you have with the id (notice) ?
work fine for me :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function noticeclose(){
	document.getElementById('notice').style.display = 'none';
}
</script>
</head>

<body>
<div id="notice" class="examdiv" style="display:block;">
	<font size="+1">
    	Kære musikstuderende.<br>Vis hensyn til hinanden, når i reserverer og følg de gældende retningslinier:<br>reserver max 2 timer pr. dag.<br><br>Vi har i eksamensperioden også åbnet for, at i kan reservere auditorierne A B og C.<br><br>Mvh. administrationen.
	</font>
	<div style="width:500px; text-align:right;"><input name="close" type="button" value="OK" align="right" onclick="noticeclose()" /></div>
</div>
</body>
</html>

Open in new window

Avatar of MortenWB

ASKER

You're fast, leakim971:)

I guess I've got only 1 object - and I can't figure out, why you can get it to work...

I will try to test your code in a seperate page.
Okay - it works allright - so it must be that the DIV displays on every refresh of the original page.

Do you have any suggestions on how one might make the DIV "remember" to stay hidden?
... i mean without storing in a database - but using a cookie or something ...
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for pointing in the right direction:) I had to spend some time understanding the cookiecode at w3scools, though - I'm a slow learner...