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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:12:50+00:00 2026-05-25T00:12:50+00:00

In HTML code my page contains: <div id=main_menu> <a href=# id=login>Link1</a> <a href=# id=logout>Link2</a>

  • 0

In HTML code my page contains:

<div id="main_menu">
  <a href="#" id="login">Link1</a>
  <a href="#" id="logout">Link2</a>
</div>
<div id="second_menu">
  <a href="#" id="information">Link info</a>
  <a href="#" id="profile">My profile</a>
</div>
<div id="menu_oustide"><a href="#" id="something">Link1</a></div>

In jQuery if I want to check if the user clicked any link in page I use this code:

$('a').click(function() { 

  // do something

});

How can I start a function if the user clicked only on links in specific div? I would like to have a function that starts if a user clicked any link only in div ID named “main_menu” AND “second_menu”, but not in “menu_outside”.

  • 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-25T00:12:50+00:00Added an answer on May 25, 2026 at 12:12 am

    Depending on what exactly you want to do, you can bind the event handler to those links only, using the descendant [docs] and multiple [docs] selectors:

    $('#main_menu a, #second_menu a').click(function() {
        // link inside #main_menu or #second_menu
    });
    

    If you don’t want to perform the same action for both, you have to bind the event handler individually.

    You could also check dynamically whether the link is a descendant of any of these element, with closest [docs]:

    $('a').click(function() {
        if($(this).closest("#main_menu").length) {
            // inside #main_menu
        }
        if($(this).closest("#second_menu").length) {
            // inside #second_menu
        }
        //...
    });
    

    But that introduces an additional overhead.

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

Sidebar

Related Questions

In my smartgwt application, the html page contains some code consisting of a div
my HTML page contains a div with an id called main, and i am
I would like to get the HTML code from a page with PHP. So
I have the following HTML Code <%@ Page Language=C# %> <html> <head> <title></title> </head>
I am building some basic HTML code for a CMS. One of the page-related
I'm creating a web page, and I can't (with html code) add a draw
Is there a way to access the page HTML source code using javascript? I
Here is my main page code: <form><iframe name=iframe_pic src=iframe.html></iframe></form> Here is my iframe.html: <script
The code segment is from a page called sites-catchup.html. There is a simple server
My index.html page for my project needs some Ruby code so I need to

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.