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 7 of 21 Topic 36376 of 37166
Post > Topic >>

Re: jQuery Query about comparing jQuery references

by Thomas 'PointedEars' Lahn <PointedEars@[EMAIL PROTECTED] > Jul 26, 2008 at 12:19 AM

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]);

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.

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.

q.e.d.


PointedEars
___________
[1] for the lack of a better word
-- 
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
 




 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 Tue Oct 14 9:38:14 CDT 2008.