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

  • Home
  • SEARCH
  • 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 7906943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:11:35+00:00 2026-06-03T11:11:35+00:00

Instead of writing return false; many times is there a way to set a

  • 0

Instead of writing return false; many times is there a way to set a collection of links such that if any of them are clicked the click function would return false;? I’d still like to have most links return true so showing code that would return true vs. return false would be particularly appreciated.

The goal is writing less code. I’d also like to know if this is a bad idea for reason I can’t understand.

  • 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-06-03T11:11:36+00:00Added an answer on June 3, 2026 at 11:11 am

    The simpliest method is binding one event listener to the document, and checking for the target: http://jsfiddle.net/gKZ7q/

    document.addEventListener('click', function(e) {
        if (e.target.nodeName.toUpperCase() === 'A') e.preventDefault();
    }, false);
    
    • For anchors with nested elements, you have to add an additional loop:

      var targ = e.target;
      do {
          if (targ.nodeName.toUpperCase() === 'A') {
              e.preventDefault();
              break;
          }
      } while ((targ = targ.parentNode) !== document.documentElement);
      // document.body should be fine. Using document.documentElement in case
      // that a fool places an anchor outside the <body>
      
    • Links can also be triggered through a key event.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a better way of writing the following method? Using LINQ maybe? Instead
Instead of writing too many sql statements in each servlet I just want to
A friend of mine is programming a web page. Instead of writing any HTML
I am writing an instead of trigger for updates that does some auditing and
In a Silverlight application, instead of consuming and writing (wcf) wrappers around messages that
I'm writing a c# program that will launch many child processes. At some time
I'm writing a csv file important script. There are two separators that can be
I have often been told that I should not use multiple return points, instead
I'm writing a function that will return database results. I need it to return
People keep telling me instead of writing shift 1 bit to the left, just

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.