Using JavaScript To Alter Attributes In A MVC Web Application
I am trying to increase the progress of the progress bar by a fixed parameter irrespective of the current value. However, I am not able to extract the current value using the .valu
Solution 1:
You just need to use parseInt
:
<script type="text/javascript">
function increase() {
var pwidth = parseInt(document.getElementById("pb1").style.width);
console.log(pwidth); // output to console
pwidth += 10;
var str = pwidth + "%";
document.getElementById("pb1").style.width = str;
}
</script>
Note: In future you can just use console.log(pwidth);
for debugging - will show value on console in the F12 Dev tools console. In the original case it was showing as undefined
.
Post a Comment for "Using JavaScript To Alter Attributes In A MVC Web Application"