"Thomas 'PointedEars' Lahn" <PointedEars@[EMAIL PROTECTED]
> wrote in message
news:488A5161.4090004@[EMAIL PROTECTED]
> Thomas 'PointedEars' Lahn wrote:
>> Aaron Gray wrote:
>>> "Henry" <rcornford@[EMAIL PROTECTED]
> wrote:
>>>> On Jul 25, 3:41 pm, Aaron Gray wrote:
>>>>> There does not seem too be anyway to test if two jQuery
>>>>> references are the same element.
>>>>>
>>>>> Given :-
>>>>>
>>>>> ... <div id="1"></div> ....
>>>>>
>>>>> Then :-
>>>>>
>>>>> alert( $("#1") == $("#1"))
>>>>>
>>>>> return false.
>>>> As would be expected because each JQuery request creates a new object
>>>> to wrap the result, and so each will be distinct from all others in
>>>> terms of identity.
>>> Yes, and no way to overload the '==' operator in Javascript, unlike in
>>> C++.
>>
>> However, the jQuery object in question might provide a property or
method
>> to
>> return the target element object of each wrapped object; a good API
>> would.
>> Then the property values or the return values of these method calls
could
>> be
>> compared as if no wrapper object was present.
>
> And there it is, as hinted by friend Firebug :)
>
> // "true"
> window.alert($("#a1")[0] == $("#a1")[0]);
Ah, I'll eat my hat :)
Not very neat or very obvious. Don't like that kind of code as it is not
easy readable by beginner, novice, or part timer.
Still think it should provide a compare method, no reason not to.
> When passed a string expression, jQuery's $() method returns a kind of
> augmented collection[1] of element objects for matching elements. Quite
> obviously, when one attempts to match by ID which must be unique
> throughout
> a Valid do***ent, the first and only item of that collection is the
> reference to the target element object.
Yes I did notice this but only half took it in, and did not follow it up
on
needing the comparison operation.
> It should be noted, though, that we are dealing with host objects here,
> and
> therefore the equals operation does not need to work like with native
> objects. (Nevertheless, no hard proof has been provided yet of an
> implementation showing different behavior.)
>
>> Despite jQuery's provably bad code quality, as the beginner that you
are
>> you
>> should be very slow to attribute things not being possible to anything
>> else
>> but your own lack of experience.
It was not obvious and obvious things should always be easy in libraries
in
my book. The less brain space I use using a library the more brain space I
have to dealing with the problem domain that I am providing a solution to.
Anyway I have part read 262 twice, its not easy digestable, have been
meaning to put in a full time reading at some point :)
Cheers Thomas,
Aaron


|