I came across a line of code using jQuery css method as below
var $container = $('#mycontainer'); <br>
var w = $.css($container[0], "width", true);<br>
jQuery documentation on css method was checked and didn't mention any variant with 3 parameters. I test the code in jsbin and it worked fine - return value is a number. if the last parameter was changed to false, the return is a string like 200px.
could anyone highlight me on this special syntax on method css?
Is it something deprecated ?
It's just the static version of css, not the jQuery element-specific instance version, so it also needs the object to apply it to.
The normal version would look like this for the code shown:
$container.css("width");
So you can see the static version just moves the target element into a first parameter. Otherwise how would it know what to apply the style too :)
true is not really a valid value for "width", so it looks like the static version uses that as a flag to say whether to return the value as a string (with the suffix px) or as a value.
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