Arnold Layne
asked on
Simple Javascript problem
This code fails the if statement when it should not and I don't know why
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
#Button1 {
background: #00aa58;
}
</style>
</head>
<body>
<input id="Button1" type="button" value="Toggle Color" onclick="toggleColor()" />
<script language="javascript" type="text/javascript">
function toggleColor() {
if (document.getElementById(" Button1"). style.back ground == "#00aa58") {
document.getElementById("B utton1").s tyle.backg round = "#ee3424";
}
else {document.getElementById(" Button1"). style.back ground = "#00aa58";}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
#Button1 {
background: #00aa58;
}
</style>
</head>
<body>
<input id="Button1" type="button" value="Toggle Color" onclick="toggleColor()" />
<script language="javascript" type="text/javascript">
function toggleColor() {
if (document.getElementById("
document.getElementById("B
}
else {document.getElementById("
}
</script>
</body>
</html>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad that I could help. Thanks for the points.
Just keep in mind, that HTML5 is also about semantic web..
ASKER