Reputation: 285
I am trying to move a div element with Javascript. I have used setInterval
function and incremented the value. My code is:
<html>
<head>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<button id="something"> click me </button>
<body>
<div id="insidename"><div>
<script>
var m = document.getElementById('something');
m.onclick = function() {
var n = 0;
window.setInterval(function() {
var w = n++;
document.getElementById('insidename').style.width = w;
}, 2000);
}
</script>
</body>
</html>
#insidename {
border: 2px solid #a1a1a1;
padding: 10px;
background: #dddddd;
width: 15px;
}
I just want to make the progress bar move when i click the button ..But the code which i wrote isn't working
Upvotes: 0
Views: 71
Reputation: 780994
The width
style needs units at the end, such as px
. So it should be:
document.getElementById('insidename').style.width = w+"px";
Upvotes: 4