Kodenfreuder wrote:
> Dear All,
> 
> I am trying to override the behavior of certain links on a page based
> on their class. It seemed like this should be easy with Prototype but
> I ran across some results I don't understand. 

It is easy.
> When I attach a click
> event to the link objects with plain innerHTML (e.g. no <b> or <i>
> tags), the event passes  the proper 'a' object to my function. If the
> innerHTML of the 'a' object contains any other objects, such as '<b>',
> it passes that instead. 

When you click on an element, the actual click could be on a child element, but
if there are onclick observers they will "bubble up" to each parent that has 
one.

If you want to always get the link then there are a couple of ways that spring
to mind. You can use up() or you can use a closure.

Using up():

  $$('a.amiabug').each(function (o) {
    Event.observe(o, 'click',foobar)
  });

  function foobar (e) {
    Event.stop(e);
    alert(Event.element(el).up('a.amiabug').inspect());
  }

Using a closure:

  $$('a.amiabug').each(function (o) {
    Event.observe(o, 'click', function() {
      Event.stop(e);
      alert(o.inspect());
    });
  ));

I prefer the closure since it's shorter and you don't have to find the element
again.

-- 
Michael Peters
Developer
Plus Three, LP


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to