Hi,

> So from now with tag a, I must use like this
> Object.prototype.toString.call(anchor)) to get object.

No, you already _have_ an object. It's just that when you do this:

    alert(anchor);

...it's exactly like doing this:

    alert(anchor.toString());

...because `alert` does an implicit "toString" operation on whatever
you pass into it, and the "toString" operation of an HTMLAnchorElement
returns its href.

Presumably you don't actually want to do an alert. You can do anything
else with the object you like.  For instance, if you wanted to remove
the anchor:

    anchor.remove();

...or if you wanted to give it a green background:

    anchor.setStyle({backgroundColor: "green"});

...etc., etc.

`Object.prototype.toString.call(x)` is useful for testing the _type_
of an object, because its return value is well-defined by the spec and
a bit more specific than `typeof` (although `typeof` is also quite
useful). But that's a side point; my main point was that the thing
being passed into your function _is_ the anchor object, not just its
href string.

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

On Jul 17, 12:48 am, Quyết Tiến <[email protected]> wrote:
> So from now with tag a, I must use like this
> Object.prototype.toString.call(anchor)) to get object.
>
> On Jul 16, 10:42 pm, "T.J. Crowder" <[email protected]> wrote:
>
>
>
> > Hi,
>
> > > But it doesn't work, it returns href of tag a instead a object.
>
> > Actually, it does work -- it's just that the default behavior of the
> > HTMLAnchorElement when you try to use it as a string is to return the
> > href (e.g., the result of its toString method), and `alert` does
> > exactly that. You can see that it's an anchor element by changing your
> > function:
>
> >     $('content').select('a[rel="dhtmlwindow"]').each(function(anchor)
> > {
> >         // alerts "typeof = object"
> >         alert("typeof = " + typeof anchor);
>
> >         // alerts "Object.toString = [object HTMLAnchorElement]"
> >         alert("Object.toString = " +
> > Object.prototype.toString.call(anchor));
>
> >         // alerts "HTMLAnchorElement.toString = (the href)"
> >         alert("HTMLAnchorElement.toString = " + anchor.toString());
> >     });
>
> > HTH,
> > --
> > T.J. Crowder
> > Independent Software Consultant
> > tj / crowder software / comwww.crowdersoftware.com
>
> > On Jul 16, 7:37 am, Quyết Tiến <[email protected]> wrote:
>
> > > I have a page html like this:
> > > <div id="content" style="padding: 100px;">
> > > <a href="#"> rel="dhtmlwindow">content</a>
> > > <div rel="dhtmlwindow">content</div>
> > > <a href="#" rel="dhtmlwindow";>content</a>
> > > <a href="#" rel="dhtmlwindow">content</a>
> > > </div>
>
> > > I want to select all tag a has rel is dhtmlwindow and this is code:
>
> > > $('content').select('a[rel="dhtmlwindow"]').each(function(anchor) {
> > > alert (anchor);
>
> > > });
>
> > > But it doesn't work, it returns href of tag a instead a object.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to