Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add checkboxes in twitter bootstrap dropdown

i am using twitter bootstrap for my project.

I want to add checkboxes in dropdown, something similar to http://jsfiddle.net/qG7c4/

File: bootstrap-dropdown.js

Example: http://twitter.github.com/bootstrap/javascript.html#dropdowns

problem is, that dropdown get closed on click of every checkbox, i don't want this to be closed on click of checkbox, so that user can select multiple checkboxes easily.

What changes i need to do in javascript for this?

like image 774
Alok Jain Avatar asked Apr 21 '12 09:04

Alok Jain


People also ask

How do I get checkbox checked in Bootstrap?

Add the checked attribute to the <input> element in order to pre-select the checkbox when the page loads. The checked attribute is a boolean attribute. The checked attribute can be used with <input type="checkbox"> and <input type="radio"> .

How do I add a dropdown list in Bootstrap?

Basic Dropdown To open the dropdown menu, use a button or a link with a class of . dropdown-toggle and the data-toggle="dropdown" attribute. Add the . dropdown-menu class to a <div> element to actually build the dropdown menu.

How do you open Bootstrap dropdown menu on hover rather than click?

Answer: Use the jQuery hover() method By default, to open or display the dropdown menu in Bootstrap you have to click on the trigger element. However, if you want to show the dropdown on mouseover instead of click you can do it with little customization using the CSS and jQuery.


1 Answers

Try stopping the propagation of the click event on your input elements like so:

$('.dropdown-menu input, .dropdown-menu label').click(function(e) {
    e.stopPropagation();
});

Demo

like image 124
Andres Ilich Avatar answered Oct 21 '22 22:10

Andres Ilich