By forbidding anyone to point out John Resigβs article specifically addressing this issue, I doubt the final answer is being proposed. But I often asked this question when I started using jQuery and came to the conclusion that this is the least harmful thing. After all, it is entirely possible that all you need is a DOM element. If you need / need to use the jQuery wrapper, then $() is only three keystrokes (or moreover you do var $this = $(this); thing). In contrast to the fact that the library always does this for you, which is associated with several function calls and memory allocation, when it may well be that you do not need it.
For example, consider:
$("input").each(function() {
There is no reason for wrapping jQuery around a DOM element. this.value is all you need for all input fields (except input type="file" , but val() won't help you either). In event handlers (where this also a βjustβ source element), you may not look at this at all.
But in this case:
$(":input").each(function() { var val = $(this).val();
... there is a genuine reason to use $(this) : Selector :input corresponds to several different types of elements ( input , select , button , textarea ), for which the value comes from different properties and val() theses that are for you.
So, I came to the conclusion that providing a raw element is performance. If you do not use it at all or use only the basic DOM properties, there is no need to wrap it in a jQuery instance. If you need / need to do this, you can do it in your code.
source share