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 364767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:28:12+00:00 2026-05-12T13:28:12+00:00

Using YUI, I have a div, with an attached listener that says if I

  • 0

Using YUI, I have a div, with an attached listener that says if I click on the div, execute a callback function. Inside the div is a series of normal html links to other pages. What I WANT to happen is that if I click a link, I go to that page. But, if I click anywhere in the div outside a link, it executes the callback function.

What is ACTUALLY happening is that if I click a link within the div, it executes the callback function for the div and then immediately navigates away to the linked page.

I know how to keep my click in the div from bubbling up to the document. But, how do I take a regular old html link and stop the click on that from firing off the click event for the div? Do I have to reformat the links as javascript links with their own callbacks and then stop propagation? Or, is there an easier way?

Amy

  • 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-12T13:28:12+00:00Added an answer on May 12, 2026 at 1:28 pm

    Seth’s got the right idea, though it’s a good idea to be a bit more specific in your checks.

    YAHOO.util.Event.on("container", "click", function(e) {
        var tgt = YAHOO.util.Event.getTarget(e);
    
        if(tgt.nodeName.toLowerCase() !== 'a') {
            YAHOO.util.Event.preventDefault(e);
    
            console.log("Not an anchor!"); //TODO: REMOVE DEBUG OUTPUT
        }
    });
    

    I built an example page at http://tivac.com/yui2/amy_events.htm just in case you want to see it in action.

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

Sidebar

Related Questions

I have a div with a width of 200px. There is text inside that
Does anyone have an example using the table object in YUI library. More specifically,
Does anyone have an example of using of populating a YUI DataTable with a
I'm using YUI to add drag drop support to a div. It also responds
I need to measure the offsetHeight of a div that is inside of a
I am using YUI reset/base, after the reset it sets the ul and li
I'm using YUI's browser history manager, and my browsers no longer report runtime errors.
I am starting using YUI 's Container control in my application to display messagebox
I've been using the YUI Components and want to begin using the Loader Utility
I am using the YUI layout manager which seems to work at an OK

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.