Interesting! That's also the same with labeling object properties. The label will be casted into their string representation.
<a href="hi.html" id="ya">asdf</a> $('#ya').click(function(){ a = {}; a[this] = 1; cache = this; }); alert(a[cache.toString()]); // alerts 1 On Jun 11, 12:16 pm, Ricardo <ricardob...@gmail.com> wrote: > Just clearing up what Pierre said: if the argument you passed to alert > () is not a string, it's .toString() method will be called. For > convenience, the toString on an anchor HTMLElement object returns it's > href. Try this: > > $('a').get(0).toString(); > or > $('a').click(function(){ > alert( this.toString() ); > return false; > > }); > > "this" in your code is still an object, it's just the output of > toString() that is different. > > cheers > -- ricardo > > On Jun 11, 1:10 am, "bensan...@gmail.com" <bensan...@gmail.com> wrote: > > > Hi all, > > > I'm confused as to why when I have: > > > $('a').click(function(){ > > alert(this); > > return false; > > > }); > > > the alert displays the URL defined in the href attribute, and not an > > object. > > > Yet, if i call like say an image, it returns the object. > > > Thanks > > ben