Nesse código o Onclick só funciona após o segundo click
<!DOCTYPE html>
<html>
<head>
<title>teste</title>
<style type="text/css">
div{
height: 100px;
width: 100px;
border: 5px solid blue;
opacity: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
function vai(){
if (document.getElementById("div").style.opacity=="0") {
document.getElementById("div").style.opacity="1"
}
else {document.getElementById("div").style.opacity="0"}
}
</script>
<p onClick="vai()">aparece</p>
<div id="div">123</div>
</body>
</html>