0

I'm creating a basic dropdown menu with twitter bootstrap. When I click on the button that opens the dropdown menu, everything works fine.

The problem is, when I try to toggle dropdown by clicking some other element on the page (I need this functionality)

$(document).on("click", ".drop-toggle", function(e) {
    console.log("working");
    $(".btn-group").toggleClass("open");
});

I can see console message, but nothing happens.

When I simply call

$(".btn-group").toggleClass("open");

it works, but it doesn't work from the event handler. Any ideas why?

http://jsfiddle.net/P2RnW/

1 Answer 1

1

You need to stop event propagation.

$(document).on("click", ".drop-toggle", function(e) {
    e.stopPropagation();
    $(".dropdown-menu").dropdown("toggle");
});

Updated Fiddle: http://jsfiddle.net/P2RnW/1/

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

1 Comment

i will try it @home, but it seems to be working. will mark as answered if it's all right :)

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.