How can I make these functions use variables for the id? I can t get the setTimeout
to work when I do.
<script type="text/javascript">
function changeBarAWidth() {
var bar = document.getElementById( firstbar );
bar.style.width = lengthA + "px";
}
function increaseBarA() {
if (lengthA < fullBarA) {
changeBarAWidth();
lengthA = (lengthA + 2);
setTimeout("increaseBarA()", 10); // <-- How do I pass "firstbar"?
}
}
function resetLengthA() {
lengthA = 0;
changeBarAWidth();
}
var barA = firstbar ;
var percentA = 80;
var fullBarA = (percentA * 2);
var lengthA = 0;
</script>
<style type="text/css">
ul {
list-style-type: none;
}
.bar {
width: 50px;
height: 5px;
background-color: red;
}
.back {
background-color: black;
height: 5px;
width: 200px;
}
</style>
</head>
<body onload="increaseBarA()">
<ul>
<li class="back">
<p class="bar" id="firstbar"></p>
</li>
</ul>
<button onClick="increaseBarA()">Test Change</button>
<button onClick="resetLengthA()">Reset</button>