View Single Post
Old 07-08-2008, 08:57 PM   PM User | #3
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
Your HTML is a bit of a mess, so I might be missing something but the following should work:
Code:
document.observe('dom:loaded', function() {  //need to do it once everything's loaded
  //then grab 'all a-tags inside countries wrapper' and call 'observe' on them with arguments:
  $$('#countries_wrapper a').invoke('observe', 'click', function(e) {
    e.stop();
    fadeOut(this.href); //in an event observer, 'this' is the element being clicked
  });
});
where fadeout is the same as yours, but with 'href' as it's argument.

Alternatively, you could use event-delegation and attach just one observer to the container:
Code:
document.observe('dom:loaded', function() {
  $('countries_wrapper').observe('click', function(e) {
    if(e.element().match('a')) { //if it's an 'a' tag
      e.stop();
      fadeOut(e.element().href);
    }
  });
});
__________________
My thoughts on some things: http://codemeetsmusic.com
And my scrapbook of cool things: http://gjones.tumblr.com
GJay is offline   Reply With Quote