Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.addClass not working

Tags:

html

jquery

css

This looks valid but it's not working. I'd like the 'huh' div to become opaque when the menu is hovered over. I tried this with fadein/out and it worked but just the once which was odd.

 <script type="text/javascript">
    $( function() {
        $('#menuNav').hover( function() {
            $('#huh').addClass('.opacity');
        }, function(){
            $('#huh').removeClass('.opacity');
        });
    });

</script>

.opacity {
    opacity: 0.3;
}
like image 375
user2608855 Avatar asked Jul 30 '13 07:07

user2608855


People also ask

What does addClass do in jQuery?

The addClass() method adds one or more class names to the selected elements. This method does not remove existing class attributes, it only adds one or more class names to the class attribute. Tip: To add more than one class, separate the class names with spaces.

How do you append a class in Javascript?

Using . add() method: This method is used to add a class name to the selected element. Syntax: element.

How do you check if an element contains a class in jQuery?

jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".


1 Answers

Use it without dot:

 $(function(){

        $('#menuNav').hover(function(){

            $('#huh').addClass('opacity');
        }, function(){
            $('#huh').removeClass('opacity');
        });
    });
like image 70
Ivan Chernykh Avatar answered Sep 21 '22 09:09

Ivan Chernykh