i need to increment the value top attribute of a div. for some reason it doesn't work.
i tried to use obj.style.top and increase the value but it doesn't work.
let sqr = document.getElementById("sqr")
let val = parseInt(sqr.style.top)
sqr.style.top = (val + 100) + "px";
body {
width: 100vw;
height: 100vh;
position: relative;
}
#sqr {
height: 30px;
width: 30px;
background-color: blue;
position: absolute;
top: 100px;
left: 100px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<link rel="stylesheet" href="index2.css" />
</head>
<body>
<div id="sqr"></div>
<script src="index2.js"></script>
</body>
</html>
I just want the square move up about 100 px. thanks.