KrMa KrMa - 1 year ago 107
Javascript Question

hover on single button in navbar

This javascript is used on the navbar on the following page

When you hover the "blog" in the navbar, there is a dropdown coming, with a white background. The button "Test" should not be a dropdown, but I would like the same function as the blog button. So when you hover the button "test", there should come the same white background. At the moment the text is only becoming blue.

Does anybody have an idea how I can do that?

//Show dropdown on hover only for desktop devices
var delay=0, setTimeoutConst;
if (('only all and (min-width: 768px)') && !Modernizr.touch) || $("html.ie8").length>0) {
$('.main-navigation:not(.onclick) .navbar-nav>li.dropdown, .main-navigation:not(.onclick) li.dropdown>ul>li.dropdown').hover(
var $this = $(this);
setTimeoutConst = setTimeout(function(){
}, delay);

}, function(){
clearTimeout(setTimeoutConst );

Answer Source

This could be done with CSS using the following declaration:

ul.nav.navbar-nav li:hover{
  background: white;

:hover is a psuedo-class that detects a mouse over the element. You can learn more about the hover pseudo-class and others like it here: Mozilla Developer Network CSS Docs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download