$(this)[0] is never needed as 'this = $(this)[0]' when in an 'each'
loop (or binding on an event, callbacks in plugins etc).
I was simply speculating what would have happened if this had been
designated a jQuery object. Hence this[0] would give you the DOM node. Read
the whole thread :)
Why do I need to wrap the this with $(this) - (when using $('#...').each) -
why isnt' that done automatically?
--
View this message in context:
http://www.nabble.com/this-verus-%28this%29-tf2810909.html#a7843947
Sent from the JQuery mailing list archive at Nabble.com.
On Dec 12, 2006, at 6:07 PM, SRobertJames wrote:
Why do I need to wrap the this with $(this) - (when using $
('#...').each) -
why isnt' that done automatically?
Hi Robert,
Actually, I just mentioned this in my blog entry last night:
'this' refers to the actual DOM element, and you can get things just like
normal JS (this.innerHTML, etc). Using '$(this)' wraps jQuery back around
it, so you can use functions like slideUp and the like.. A lot of the time
you wont need jquery to accomplish something.
On 12/12/06, SRobertJames
Since jQueryizing an element
- involves a small performance hit and
- not every developer's requires a jQuery object in eqch
it makes more sense to simply provide the element itself inside each. This
way developers can do $(this) if they need to.
Blair
On 12/13/06, SRobertJames [EMAIL
...you would have to do $(this)[0], so it's extra typing either way. ...
Er in that example it should be this[0].
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
Hi,
Why do I need to wrap the this with $(this) - (when using $('#...').each) -
why isnt' that done automatically?
Most of the time you use each(), because you want to access the DOM Objects.
That is exactly what you get as this. In most cases you need a jQuery Object
you can do your work
I see. Thanks for the clarification.
As a newcomer, I will say that this should be shown in the
docs/examples. I had to undergo a lot of trial, error, and head
scratching before I figured this out. (I don't think any of the docs
for $().each() show this).
BTW, what things do you need the DOM
DOM is alot quicker.
On 12/12/06, Robert James [EMAIL PROTECTED] wrote:
I see. Thanks for the clarification.
As a newcomer, I will say that this should be shown in the
docs/examples. I had to undergo a lot of trial, error, and head
scratching before I figured this out. (I don't think any
Generally the jQ object has methods that
- can apply to the entire selected array of elements. Some extra
methods are included for completeness - e.g. attr(href,#) sets the
href attribute on all selected elements, but attr(href) will return the
href value of the first selected element.
10 matches
Mail list logo