JQuery removeClass except current id

[ Live Demo ]

I have a navigation menu that displays a certain state when it hangs, and also displays the text in another div.

In case the user does not interact with the menu, the automatic cycle of divs is by itself, and the corresponding hang state is displayed in the navigation menu, as if the user was interacting.

However, since this is cyclic, if the user is pointing to another link in the navigation menu, I need to remove the Class on the previously selected item.

How do I write: "if id currently does not hang id, then removeClass (" hoverBold ") on all other navigation links"

+3
source share
5

hoverIn:

links.removeClass('hoverBold');

, a:hover.sliderLinks hoverBold

: http://www.jsfiddle.net/MXSkj/1/

+2

jQuery not().

- ...

$('.myMenu').hover(function() {
    $('.myMenu').not(this).removeClass('hoverBold');
});
+6

- ?...

$('#nav li').mouseover(function(){
 //remove from others
 $('#nav li').removeClass('hoverBold');
 //add to this 
 $(this).addClass('hoverBold')
});
0

hoverBold .

$(".sliderLinks").hover(function(){
   $(".sliderLinks").removeClass("hoverBold");
   $(this).addClass("hoverBold");
},function(){
   //..resume the automatic behaviour 
});

is() , $(".sliderLinks").each(), ,

0

. filter

$(".myMenu").click(function() {
    // store current object
    var that = this;
    $(".myMenu").filter(function() {
        // check object in list is not current object
        return this != that;
    }).removeClass("hoverBold");

});

, . false (.. This == that), .

0

Source: https://habr.com/ru/post/1786732/


All Articles