+ 3
Why this code don't work well? I need that every time you click the button the progressbar increase 20% but it don't do nothing.
js: ... function aaa() { } function qq() { let pre=document.querySelector("#pre"); var i=100; let id=setInterval(function(){ i-=20; if(i>=0){ pre.value=i} else { clearInterval(id); if (aaa()) { pre.value=i+=40; } } },1000); }; html: <p id="we">Sueño</p> <button id="me" onclick="aaa()">Dormir</button><progress value="100" max="100" id="pre"></progress> ////I need that every time you click the button the progressbar increase 20%
2 Réponses
+ 3
<body>
<progress id="pre" value="20" max="200"></progress>
<button onclick="add()">+20</button>
<script>
add = ()=>{
var valtag = document.querySelector("#pre");
var val = parseInt(valtag.getAttribute("value"));
if(val<200){
val =(val)+20 ;
}
valtag.setAttribute("value",val);
}
</script>
</body>
+ 1
.value is used for input tags value.
But here
You are dealing with attributes
Use
getAttribute() & setAttribute()