Why $(this) doesn't work here?
Hi,
I did some googling to understand the difference of $(this) and
this, with the following result:
You need
$(this)
for jQuery functions, but when you want to access basic javascript methods of the element that don't use jQuery, you can just use
this.
My understanding is that $(this) is just the jQuery version of
this.
But if I'm right, why the following code doesn't work if I replace
this with $(this)??
- var tab = ["John", "Steve", "Ben", "Damon"];
- $list = $('#list');
- $.each($(tab), function(){
- $list.append("<li>" + this + "</li>")
- });
Thanks