I have some code that gets the width of a button, but it always returns the width of the button with "px" on the end. Is there an easy way (without creating a function that removes the last two characters) of getting the width without the "px" part, but still in pixels?
jsfiddle example
<button name="test" id="mybutton" onclick="alert(this.style.width);" style="width:200px;">Click me</button>
Thanks in advance
Hey a quick a simple answer for this is to use parseInt on the number
<button name="test" id="mybutton" onclick="alert(parseInt(this.style.width,10));" style="width:200px;">Click me</button>
See the fiddle here http://jsfiddle.net/XdADS/6/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With