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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:38:05+00:00 2026-06-09T02:38:05+00:00

I need to click on a document to call some function, but the problem

  • 0

I need to click on a document to call some function, but the problem is that when I click on some element that want it doesnt react, so the code:

<body>

<div class="some_element">
some element
</div>



</body>

and js:

$(document).click(function(){

   //something to happen

})

and now if I click on the div with class="some_element" the document.click event will be called, but I need to call that event ONLY when I click on the document; or it is possible the make this element an exception?

More detailed:

$('#forma').click(function(e){

    e.stopPropagation();
    
    $('#assignment_type_list').slideUp();


})

Lets say #forma – its a parent element of those element, so when I click on the page I want to slideUp someElement and:

$('#assignment_type_select, #assignment_type_label').click(function(){
    
        $('#assignment_type_list').slideToggle();
            
            })

this is the elements when they are clicked the other element is toggled, but the problem is that when I click on this elements the $('#forma').click – also executes, because its parent and the e.stopPropagation() – doesn’t help.

  • 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-09T02:38:07+00:00Added an answer on June 9, 2026 at 2:38 am

    All this stopPropagation stuff is right, though this’ll cause your script to throw errors on older versions of a certain browser. Guess which one? a cross-browser way:

    $('#elem').click(function(e)
    {
        e = e || window.event;//IE doesn't pass the event object as standard to the handler
        //event would normally work, but if you declared some event variable in the current scope
        //all falls to pieces, so this e || window.event; thing is to be preferred (IMO)
        if (e.stopPropagation)//check if method exists
        {
            e.stopPropagation();
            return;
        }
        e.cancelBubble = true;//for IE
    });
    

    However, you wanted to check if the element that was actually clicked, is the one you need. The problem with that is, that the way the event is passed through the DOM. In W3C browsers the event is first passed to the document, and then clambers down to the element that was actually clicked (propagates through the dom).
    By contrast IE dispatches its events on the element itself, and then sends it up to the document (except for the change event triggered by select elements… to add insult to injury). What this effectively means is that a click event that is registered in to body element in W3C browsers might be on its way to a checkbox of sorts, or it could be a click inside an empty div.
    Again, in IE, when a click event reaches the body tag, it could have been dispatched too any element on the page. So it may prove useful in your case to google: event delegation, or turn to jQuery’s .delegate() method.

    Or check the event object to see if the event is allowed to propagate through or not:

    var target =  e.target || e.srcElement;//target now holds a reference to the clicked element
    

    The property names neatly show the difference between the bubbling model and the propagating one: in the first case (srcElement), the event is coming from a source element in the dom. In the W3C propagating model, the event is cought while it’s headed for a target element somewhere in the dom.
    Look at it like a heat-seeking missile (w3c) versus a shower of debris after the target was shot down (IE, always the destructive one, and in this case often to late to respond to the events, and therefore to late to handle them:P)

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

Sidebar

Related Questions

I have this piece of code: $(document).on(click, #breadNavMain, function() { for(var i = 0;
I need to trigger a click function assigned to a checkbox, but without actually
i have some jquery logic, below is the code $(document).ready(function() { $('<ul class=className><\/ul>').insertBefore('.divClassName'); $.each(jsArray,
I need to click items on ItemCollection and transfer it to CartCollection. But i
I have a hidden button on a form that I need to click in
I would really need to programmatically click on all nodes in the collection, but
I need some help to do a simple click in a listview item to
I have some jQuery with an Ajax call that looks like this: $.ajax({ type:
I need help with adding to a database. I want to call a javascript
On the click of a button, I call a JavaScript function. After getting the

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.