I have green circle in my html file (index.html) and I want to change the color by clicking a button which runs the JavaScript (change.js).
Here is index.html:
<!DOCTYPE html>
<html>
<body>
<style type="text/css">
#circle {
width: 50px;
height: 50px;
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
background: green;
}
</style>
<h1>Change Colors</h1>
<div id="circle"></div>
<p>
<div>
<button type="button" onclick="change.js">Change Color</button>
</div>
</p>
</body>
</html>
Here is change.js:
function myFunction() {
document.getElementById("circle").style.background="red";
}