如何选择:悬停不在某个选择器中 [英] How to select a:hover that's not in a certain selector
问题描述
我想要风格 a
不在某个id的元素。例如,假设这是我的HTML:
I would like to style a
elements that are not in a certain id. For example, let's say this is my HTML:
<div id="boat">
<a href="#">I'm in a boat! ☻</a>
</div>
<a href="#">☹</a>
现在,假设我只想对 a
元素不在船上。我期待类似 a:hover:not(#boat a)
工作,但唉,它不。
Now, let's say I only want to style the a
element that's not in a boat. I expected something similar to a:hover:not(#boat a)
to work, but alas, it doesn't. Is there a way I can do what I want to do?
推荐答案
当涉及到jQuery选择器 a:hover
将选择具有CSS伪类的所有
应用于它(即 a
元素:hover a
元素,当前用鼠标悬停)。
When it comes to jQuery selectors a:hover
will select all the a
elements which have the CSS pseudo class :hover
applied to it (i.e. a
elements which are currently being hovered over with the mouse).
过程和不是样式选择,请选择您正在讨论的元素:
This is the selection process, and not the styling selection, to select the elements you are talking about, try this instead:
$('a:not(#boat a)')
DEMO: / strong> http://jsfiddle.net/marcuswhybrow/AMWhU/
如果悬浮jQuery效果是哇,你是在一旦你做出选择只是绑定事件照常:
If a hover jQuery effect is waht you are after the once you have made the selection just bind the event as usual:
$('a:not(#boat a)').hover(function() {});
这篇关于如何选择:悬停不在某个选择器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!