1

Im trying to remove a class once the user hovers over a link.

Here is the HTML:

<a href="#" id="menu_fonctionalites">Fonctionalites</a>


<div id="commercial_dd_total_FONCTIONALITES" class="menu_hidden">
<a class="commercial_dd_bg">Item One</a>
</div>

JS:

<script type="javascript">  
$(document).ready(function(){
$("#menu_fonctionalites").hover(
function () {
$("#commercial_dd_total_FONCTIONALITES").removeClass("menu_hidden");
}
);  
}); 
</script>

This isn't working.... any ideas about what I've done wrong?

1
  • 2
    the type should be "text/javascript" Commented Nov 22, 2010 at 4:00

2 Answers 2

1

http://jsfiddle.net/tuFru/1 it appears to be working here. You might include the CSS and describe what exactly isn't working for you. I updated it to take advantage of the second argument for hover as defined below:

Description

Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.

version added: 1.0.
hover( handlerIn(eventObject), handlerOut(eventObject) )

handlerIn(eventObject)A function to execute when the mouse pointer enters the element. handlerOut(eventObject)A function to execute when the mouse pointer leaves the element.

The .hover() method binds handlers for both mouseenter and mouseleave events. We can use it to simply apply behavior to an element during the time the mouse is within the element.

Calling $(selector).hover(handlerIn, handlerOut) is shorthand for:

$(selector).mouseenter(handlerIn).mouseleave(handlerOut);

See the discussions for .mouseenter() and .mouseleave() for more details.

Sign up to request clarification or add additional context in comments.

Comments

1

If you are just trying to toggle visibility you could probably just add the normal class for the div styling and toggle it using the jQuery hide()/show() methods.

2 Comments

Oh yeah, I totally forgot about toggle. I'll probably use that. But can you see why the removeClass isn't working?
I'm getting the same result as Gabriel - no problems in fiddle. I think might just be overcomplicating this with CSS. Still reccommending using hide/show. Good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.