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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:55:54+00:00 2026-05-23T11:55:54+00:00

How do I handle clicks on an element but not clicks on links within

  • 0

How do I handle clicks on an element but not clicks on links within that element?
Say I have the following

<div class="section">
    Some text blah blah
    <a href="#">Link</a>
</div>
<script>
    $(".section").click(function() {
        // code to expand/collapse section
    });
</script>

And I want users to be able to click on .section in order to expand/collapse it but I don’t want that to happen if they clicked on a link within that section.

  • 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-23T11:55:54+00:00Added an answer on May 23, 2026 at 11:55 am

    You can check the event target, and only do something if it is the div. Here is one example:

    $(".section").click(function(e) {
        if(e.target.tagName !== "DIV") {
          //Not the div! 
        }
    });
    

    You can test various properties of the target, so if for example you had other child div elements, but didn’t want to register clicks on those, you could use the className property:

    e.target.className !== "section"
    

    Here is a working example (using the tagName property).

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

Sidebar

Related Questions

I have a page with links of class 'dialog' that generate in JQueryUI dialog
I've got a window that I handle WM_NCLBUTTONUP messages, in order to handle clicks
I have an element contained in a parent element with the class active ,
[updated] The 1st jQuery section below dynamically creates an a.open-popup element. But after I
Let's say I want to handle all links on a page, via a special
I have the following snippet, but it doesn't work. Probably the live() handler is
I have a bunch of links with non-pre-determined id's like so: <a href=# class=remove_pid
i have a function to handle click of clickedcell. I want to exctract value
I have a s:List component. I want to handle a click event to know
It is said that when we handle a "click event", returning false or calling

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.