<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./files/jquery-1.11.2.min.js"></script>
<script src="./files/bootstrap.min.js"></script>
<link rel="stylesheet" href="./files/font-awesome.min.css">
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, NanumBarunGothic, NanumGothic, "Apple SD Gothic Neo", sans-serif;
}
a {
font-size: 36px;
font-weight: 500;
text-decoration: none;
transition: color 0.3s;
color: #0099cc;
background-color: transparent;
box-sizing: border-box;
}
a:hover {
color: #4dd2ff;
outline: none;
border-bottom: 1px dotted;
}
hr {
margin-bottom: 23px;
border: 0;
border-top: 1px solid #b8b8b8;
}
.button2 {
position: absolute;
}
</style>
<script>
function alertKWEB() {
window.alert("Me too");
}
function alertKWEB2() {
window.alert("K★W★E★B");
}
function moveButtonRand() {
var buttonTag=document.getElementsByClassName('button2');
var positionTop=Math.floor(Math.random()*90+5);
var positionLeft=Math.floor(Math.random()*90+5);
buttonTag.style.top=positionTop+"%";
buttonTag.style.left=positionLeft+"%";
}
</script>
</head>
<body>
<div class="main" style="text-align: center; width: 100%; height: 100%">
<h1><a href="https://kweb.korea.ac.kr/">Do you love KWEB?</a></h1>
<hr>
<button onclick="alertKWEB()">I do</button>
<button class="button2" onclick="alertKWEB2()" onmouseover="moveButtonRand()">.....</button>
</div>
</body>
</html>
I want to make the second button move to a random position when I put the cursor over it. I don't understand why this does not work; please help! This is my school homework which entails using the JS DOM, so please do not suggest other ways.