Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: add regexp to antd 
Javascript :: data-id html javascript 
Javascript :: get function parameters count javascript 
Javascript :: javascript get referrer 
Javascript :: Group array of strings by first letter 
Javascript :: stop a function javascript 
Javascript :: add required attribute javascript 
Javascript :: javascript 1 line if 
Javascript :: set timeout for loop 
Javascript :: javascript random element from array 
Javascript :: discord client.send_message js 
Javascript :: npx http server 
Javascript :: laravel link custom javascript file 
Javascript :: delete node module 
Javascript :: array map destructuring 
Javascript :: jquery next sibling with class 
Javascript :: react select npm 
Javascript :: javascript react useState update object 
Javascript :: find and filter in javascript 
Javascript :: javascript function to open file browser 
Javascript :: play sound with keydown javascript 
Javascript :: javascript select input text on focus 
Javascript :: icon button react 
Javascript :: json query online 
Javascript :: como diminuir quantidade de casas decimais javascript 
Javascript :: javascript dynamic arrays 
Javascript :: increased the value of a counter when a button is clicked in js 
Javascript :: remove comma from string jquery 
Javascript :: add array to array javascript 
Javascript :: react append classname 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =