user3347903 user3347903 - 3 months ago 20
jQuery Question

Bootstrap: Remake jQuery function to work on hover instead of click

I'm using bootstrap and got stuck.
The code below works on click. How can I remake it so it would work on hover? I'm a noob in jQuery..

$(document)
.on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
var $btn = $(e.target)
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
Plugin.call($btn, 'toggle')
e.preventDefault()
})
.on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
$(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type))
})
}(jQuery);


p.s. It seems like the important string is '[data-toggle^="button"]', since deleting this ruins the functionality
p.p.s. I've already read How to make twitter bootstrap menu dropdown on hover rather than click but it didn't help. I'd prefer not to ruin what I'v already done

Answer

Easy solution, is to make CSS

.dropdown:hover .dropdown-menu {
    display: block;
 }