Answers for "javascript calculate percentage to pixel"

0

javascript calculate percentage to pixel

<div id="div-1" style="width: 1000px;">
    <div id="div-2" style="width: 10%;"></div>
</div>

<script language="javascript">                
    var percents = parseInt(document.getElementById("div-2").style.width);
    var parentWidth = parseInt(document.getElementById("div-1").style.width);
    var pixels = parentWidth*(percents/100);
    alert(pixels); // will print "100"
</script>
Posted by: Guest on October-22-2021

Code answers related to "javascript calculate percentage to pixel"

Code answers related to "Javascript"

Browse Popular Code Answers by Language