Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5938437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:41:08+00:00 2026-05-22T15:41:08+00:00

I seem to get something fundamentally wrong. I have this HTML <div id=thumbnails> <a

  • 0

I seem to get something fundamentally wrong. I have this HTML

<div id="thumbnails">
    <a href="#image-0">
        <img src="blabla-1.jpg" />
    </a>
    <a href="#image-0">
        <img src="blabla-1.jpg" />
    </a>
    <a href="#image-0">
        <img src="blabla-1.jpg" />
    </a>
</div>

and this JavaScript (MooTools library in use)

document.id('thumbnails').getElements('a').each(function(image_link, image_link_index)
{
    image_link.addEvent('click', function(evt)
    {
        if (evt.target.get('tag') == 'a')
        {
            evt.stop();
            console.log('a tag', evt.target);
        }

        console.log(':-(', evt.target);
    });
});

Strangely I never get to that a element. I’m sure I’m misunderstanding something basic here.

You can play around with the code at http://jsfiddle.net/maryisdead/kHBE3/8/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:41:08+00:00Added an answer on May 22, 2026 at 3:41 pm

    why are you reinventing the wheel? event delegation is not something to be taken lightly – and you should use the built-in event-delegation (since 1.4.1) http://mootools.net/docs/core/Element/Element.Delegation

    your code would change to:

    document.id('thumbnails').addEvent('click:relay(a)', function(evt, el) {
        evt.stop();
        console.log(':-)', el.get("tag") == 'a', this.get("tag") == 'a');
    });
    

    where the relay() pseudo can take any selector you like – eg. a.foo or a[href=#]

    keep in mind that in 1.2 the event delegation was sort of experimental and somewhat less than perfect – when it came to mouseover:relay() or focus:relay(input[type=text]) you can get some unexpected results in different browsers – issues addressed in 1.3.2 iirc. Also, change events on checkboxes and radios in old ie6/7/8 revert to onpropertychange and may not bubble.

    in any case, yours fails to come through to the anchor link as the event.target as the event itself BUBBLES from the top down. i.e. it will start from img > a > thumbnails but it won’t raise different events for both – it will be the same event.target on both all 3 elements yet -> this === a

    what you can do though is console.log(this.get("tag") === 'a')); // true – even though the initial target was the child of this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page containing a series of tags like this <a class=IMG href=#
I would like to do something like the following but can't seem to get
I can't seem to get a custom action working. I might be doing this
My problem is that I can't seem to get the image from my bundle
I have a string 2010-08-02 12:13:06.0 and need to get something like Fri Aug
Maybe I am just forgetting something, but I cannot seem to get NUnit to
I can't seem to get my application up and running on my dev server
I can't seem to get it to work. It works fine in Firefox, but
I can't seem to get it to work. Perhaps I'm not even testing it
can't seem to get the syntax right in order to pass the AttID variable.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.