The so-called acquisition of pixel values without units is obtained such as the width of the element, height, font size, margin, padding equivalent but minus the pixel units.
For example: the width of an element is 100px, now I want to get this value but without the unit "PX", how do you solve this problem? My solution is to:
For example, by clicking on a button to get the value, you should write a function at this point, and then call the function when the button is clicked.
Function par (str) {
var num = str.replace ("px", "");
var num = parseint (num);
Alert (NUM)
}
Here, str.replace ("px", "") means to replace the PX in the string with a null, that is, to remove the PX, but even if the PX is removed, the value is still a string type, so now to do is to convert the string type to a numeric type, here I use the parseint method.
Now you can write it by clicking Execute with the button.
<input type= "button" onclick= "par (' 100px ')" value= "Click to get pixels without units" >
JS gets the pixel value without units