Posted By

wdso on 04/22/09


Tagged

event


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wdso


Smart on-click event handler for parent element


 / Published in: JavaScript
 

  1. // attach onclick event listener to all .item(s)
  2. $$('#content .toggle_item').each(function(item) {
  3. item.addEvent('click', function(event) {
  4. var target = $(event.target);
  5. // check that target is as expected
  6. if(target.hasClass('toggle')) {
  7. this.toggleClass('active');
  8. target.toggleClass('active');
  9. target.hasClass('active') ? target.innerHTML = 'verstecken…' : target.innerHTML = 'mehr…';
  10. }
  11. })
  12. });

Report this snippet  

You need to login to post a comment.