Each infrequently I find out about a JavaScript property that I want I had identified about years earlier — valueAsNumber
is one in all them. The valueAsNumber
offers the worth of an enter[type=number]
as a Quantity sort, as a substitute of the standard string illustration once you get the worth:
/* Assuming an <enter sort="quantity" worth="1.234" /> */ // BAD: Get the worth and convert the quantity enter.worth // "1.234" const numberValue = parseFloat(enter.worth, 10); // GOOD: Use valueAsNumber enter.valueAsNumber // 1.234
This property permits us to keep away from parseInt
/parseFloat
, however one gotcha with valueAsNumber
is that it’ll return NaN
if the enter
is empty.
Thanks to Steve Sewell for making me conscious of valueAsNumber
!
PSA: quantity inputs have a `.valueAsNumber` property that you could be discover helpful pic.twitter.com/1QwdAW16CC
— Steve Sewell (@Steve8708) March 31, 2022
Creating Scrolling Parallax Results with CSS
Introduction For fairly a very long time now web sites with the so referred to as “parallax” impact have been actually in style. In case you haven’t heard of this impact, it principally consists of totally different layers of pictures which are shifting in numerous instructions or with totally different pace. This results in a…
jQuery Countdown Plugin
You have most likely been to websites like RapidShare and MegaUpload that permit you to obtain information however make you wait a specified variety of seconds earlier than providing you with the obtain hyperlink. I’ve created an identical script however my script means that you can animate the CSS font-size…