3

I looked at the bootstrap code for dropdown.js in github repo and would like to know what do they use to handle click outside/elsewhere functionality ?

If anyone can post an answer with a diagram for understanding, that would be very helpful..

Piyush Chauhan
  • 1,523
  • 2
  • 24
  • 37
  • I don't know the answer for this one, but if I had to guess it be that they use `$('body').on('click', function(e) { // hide dropdown unless e.target includes the dropdown`. Here's a similar issue that has to do with popovers, but is about the same concept: http://stackoverflow.com/questions/11703093/how-to-dismiss-a-twitter-bootstrap-popover-by-clicking-outside – Sean Huber Aug 02 '15 at 05:44

1 Answers1

1

In the current version of dropdown.js, when the dropdown is opened, toggle() is executed and they add a backdrop <div> on the page that covers the entire screen behind it. The new div gets a click event that calls clearMenus().

haferje
  • 958
  • 2
  • 14
  • 21
  • can you also point out the repository code lines and paste a link here too. That would be very helpful for reading and research. @haferje – Piyush Chauhan Aug 02 '15 at 08:18
  • 1
    It isn't real helpful to other people to list the line numbers, as the files will change over time, but for the code as of today, you can start [here](https://github.com/twbs/bootstrap/blob/027b7efd792f4fab065bc6e71d8d2573cd13cadb/js/dropdown.js#L71L74). – haferje Aug 02 '15 at 17:11