Should You Use the ‘var $this = $(this);’ Syntax in jQuery?
A common jQuery coding practice
var $this = $(this);
There are a few benefits:
var $this = $(this);
There are a few benefits:
- $(this) is only evaluated once (minor efficiency)
- You can use a more descriptive name for $(this). I’m using var $MyCurrentBook = $(this);
- By preceding the variable name with the $ sign, you’re reminding yourself that it’s a jQuery variable, not just a plain old JavaScript variable.
Comments
Post a Comment
Thanks
Warm regards,
Karthikeyan.T
tkarthikeyan@gmail.com
www.carthworks.com
Call us 09445 2772 06