开发者

Using the jQuery hover function

Using the jQuery hover function, I want to set an iframe src value to null when the user clicks on the menu item that matches the following:

<li class="current">
<a class="sf-with-ul" href="#">CTI</a>

I basically want to check when the user clicks on the top level menu item when the class is "sf-with-ul" and a href is "#"

I am unsure how to do this and then attach hover function when the user clicks on the above selector.

I only want 开发者_运维技巧to fire the hover function at the top/parent level (first occurrence only).


You'd probably want to look into jQuery selector syntax. http://api.jquery.com/attribute-equals-selector/

If I am understanding your problem correctly, I'd try something like this.

var clicked = false;

$(".sf-with-ul[href='#']").click( function () {
  clicked = true;
});

// Only hover if it's clicked

$("selector").hover( function () {
  if (clicked) {
  // do something hover over
}
}, function () {
 if (clicked) {
  // do something hover out
}
});

EDIT: Another answer uses .bind to enable the hover which I like more, makes it a little more elegent.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜