Hi,

> But it does not work again.

It does for me, if I fix the various typos in the HTML:
http://jsbin.com/eweyo4

"Doesn't work" is not really a useful description of a problem. When
describing a problem for people to help with, these are the sorts of
questions you typically want to answer: Doesn't work *how*? What
happens? What do you expect to have happen instead? Do you see any
errors? If so, what are they? What have you already checked to try to
figure it out? Etc., etc.

You probably want to walk through the code in a debugger like Firebug
(for Firefox), Dev Tools (for Chrome; built in), VS.Net or Script
Debugger (for IE), etc., to figure out what's going wrong on the page.

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


On Jul 17, 4:45 pm, Quyết Tiến <doquyett...@gmail.com> wrote:
> I do this:
> $('content').select('a[rel="dhtmlwindow"]').each(function(anchor) {
>     anchor.observe('click', function() { alert ('aaaa'); });
>
> })
>
> But it does not work again.
>
> On Jul 17, 8:29 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
>
>
>
> > 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 / comwww.crowdersoftware.com
>
> > On Jul 17, 12:48 am, Quyết Tiến <doquyett...@gmail.com> 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" <t...@crowdersoftware.com> 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 <doquyett...@gmail.com> 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.- Hide 
> > > > > quoted text -
>
> > - Show quoted text -

-- 
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 prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to