Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > Re: jQuery Quer...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 21 Topic 36376 of 37128
Post > Topic >>

Re: jQuery Query about comparing jQuery references

by "Aaron Gray" <ang.usenet@[EMAIL PROTECTED] > Jul 25, 2008 at 11:48 PM

"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
 




 21 Posts in Topic:
jQuery Query about comparing jQuery references
"Aaron Gray" &l  2008-07-25 15:41:15 
Re: jQuery Query about comparing jQuery references
Henry <rcornford@[EMAI  2008-07-25 08:17:11 
Re: jQuery Query about comparing jQuery references
"Aaron Gray" &l  2008-07-25 19:08:52 
Re: jQuery Query about comparing jQuery references
Thomas 'PointedEars' Lahn  2008-07-25 22:56:56 
Re: jQuery Query about comparing jQuery references
"Aaron Gray" &l  2008-07-25 23:00:58 
Re: jQuery Query about comparing jQuery references
Thomas 'PointedEars' Lahn  2008-07-26 00:25:30 
Re: jQuery Query about comparing jQuery references
Thomas 'PointedEars' Lahn  2008-07-26 00:19:13 
Re: jQuery Query about comparing jQuery references
"Aaron Gray" &l  2008-07-25 23:48:02 
Re: jQuery Query about comparing jQuery references
dhtml <dhtmlkitchen@[E  2008-07-25 11:45:01 
Re: jQuery Query about comparing jQuery references
"Aaron Gray" &l  2008-07-25 20:38:31 
Re: jQuery Query about comparing jQuery references
dhtml <dhtmlkitchen@[E  2008-07-25 16:50:30 
Re: jQuery Query about comparing jQuery references
Thomas 'PointedEars' Lahn  2008-07-26 03:17:53 
Re: jQuery Query about comparing jQuery references
dhtml <dhtmlkitchen@[E  2008-07-25 18:39:34 
Re: jQuery Query about comparing jQuery references
Thomas 'PointedEars' Lahn  2008-07-26 04:25:49 
Re: jQuery Query about comparing jQuery references
dhtml <dhtmlkitchen@[E  2008-07-26 00:23:39 
Re: jQuery Query about comparing jQuery references
Thomas 'PointedEars' Lahn  2008-07-26 13:01:51 
Re: jQuery Query about comparing jQuery references
dhtml <dhtmlkitchen@[E  2008-07-26 10:25:29 
Re: jQuery Query about comparing jQuery references
Thomas 'PointedEars' Lahn  2008-07-26 21:32:17 
Re: jQuery Query about comparing jQuery references
dhtml <dhtmlkitchen@[E  2008-07-26 16:16:25 
Re: jQuery Query about comparing jQuery references
Thomas 'PointedEars' Lahn  2008-07-27 14:51:21 
Re: jQuery Query about comparing jQuery references
Lasse Reichstein Nielsen   2008-07-27 15:53:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 14:53:00 CDT 2008.