I have just stumbled upon the following webpage and am somewhat intrigued by the use of the in keyword.
http://diveintohtml5.ep.io/examples/input-autofocus-with-fallback.html
They are using this syntax for fallback when web browser doesn't support the autofocus attribute. So this would lead me to believe that this syntax is valid.
The in operator checks if a property is defined on an object. So, this is valid Javascript and is accepted in almost all browsers.
In this case, the code is checking if "autofocus" is a property of a new element. If it is, then most likely the browser supports autofocus and will not need .focus() (or someone may be extending prototypes).
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