开发者

jQuery .hover issue

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(开发者_StackOverflow"menu_hidden");
}
);  
}); 
</script>

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜