Hello I am starting off in Javascript / CSS. I am currently practicing.
I am trying to add a button on my page that changes the color of my navbar whenever it is clicked. Is there a way to get a randomly generated color? Or do I have to list the colors in the code?
This is my current test page.
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: blueviolet;
}
li {
float: left;
}
li a {
display: inline-block;
color: white; /*changes text of the nav bar */
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
</style>
</head>
<body>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
<script>
function myFunction() {
document.body.style.backgroundColor = "red";
}
</script>
</body>
</html>
Thank you.