0
function datePicker(event)
{
//do something`enter code here`
}

document.onclick=function() {
//do something
}

When I call datePicker() function I want to prevent the calling second method . How to do that ?

1 Answer 1

3

Use event.stopPropagation() to stop the event bubbling up to the document click listener:

function datePicker(event)
{
    event.stopPropagation();
}

You can also use event.stopImmediatePropagation() to stop sibling elements receiving the event too, if necessary: jquery: stopPropagation vs stopImmediatePropagation

jQuery Example with IE8 catered for: http://jsfiddle.net/kHT2A/2/

Sign up to request clarification or add additional context in comments.

3 Comments

Is the function datePicker actually receiving an event, or just a parameter called event?
stopPropogation isn't available in IE8 and lower, and stopImmediatePropagation isn't available natively in any browser.
Just found out it's prop/a/gation, not prop/o/gation - you learn something new every day :) Updated answer with the correct spelling Also, see jsfiddle.net/kHT2A/1 for a working example with jQuery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.