I’m trying to hide a div, and I can’t seem to get it working properly. Here’s my code:
<head>
<title>Home - Chrome</title>
<link rel="stylesheet" href="main.css">
<script src="jquery.js"></script>
<script>
function 1Hide() {
document.getElementById('div1').style.display = 'none';
}
</script>
</head>
<body>
<div id="div1">
</div>
<a onclick="1Hide" href="javascript:void(0);">Click</a>
</body>
CSS:
#div1 {
height: 100;
width: 700;
margin: 30 auto 0 auto;
background: #FFFFFF;
}
Identifiers cannot start with numbers. Change
1Hideto something likeHide1instead. Moreover, to call a function, you add parenthesis to the end of the identifier like so:Hide1();.This will call the function. Your HTML should look like the following:
Notice the operator
()appended to the end of the function name. Whenever you want to call functions this is the syntax you use.