• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Javascript/CSS/HTML

Dixter

Amateur Web Developer
Joined
Mar 31, 2009
Messages
660
Reaction score
11
Hello, I've recently been learning html css and javascript. For some reason when I try to use javascript and CSS for the same webpage the CSS doesn't work.

Here's what I'm using as a script:

HTML:
<html>
<head>
<style type="text/css">
<link rel="stylesheet" type="text/css" href="thestyle.css"/>
body 
{
background-color:red;
} 
</style>
<script type="text/javascript">
function show_alert()
{
alert("Why do people always press the button they are told not to push?")
}
</script>
<title>Scorpia</title>
</head>
<body>
<input type="button" onclick="show_alert()" value="Do NOT press this button!"/>
</body>
</html>

Only the button is visible, the background isn't red. Why is this happening?
 
Last edited:
Code:
<html>
<head>
	<title>Scorpia</title>
	<link rel="stylesheet" type="text/css" href="thestyle.css"/>
	<style type="text/css">
		body {
			background-color: red;
		} 
	</style>

	<script type="text/javascript">
		function show_alert() {
			alert("Why do people always press the button they are told not to push?");
		}
	</script>
</head>

<body>
	<input type="button" onclick="show_alert()" value="Do NOT press this button!" />
</body>
</html>
 
It's rather tabing, than spacing and no it doesn't matter, I like to tab code because it looks neater. Also it doesn't matter if you use title above style or under, it's all on you where you put it (aslong it's inside head section). Your mistaken was inside script, you didn't add semicolon ( ; ) after alert, also you used link element inside style.
 
Last edited:
Thanks! xD I haven't practiced this ina while so I forgot a lot. I'm trying to learn more though, thanks again for your help :)
 
Back
Top