Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 悬停时选择兄弟姐妹_Javascript_Jquery_Html_Css_Jquery Selectors - Fatal编程技术网

Javascript 悬停时选择兄弟姐妹

Javascript 悬停时选择兄弟姐妹,javascript,jquery,html,css,jquery-selectors,Javascript,Jquery,Html,Css,Jquery Selectors,我有一个类似于HTML的代码: <div class="blog_highlight"> <ul class="calendar"> <li><a href="#">Nov</a></li> <li><a href="#">25</a></li> </ul> <ul class="commentaries"> <li><a hre

我有一个类似于HTML的代码:

<div class="blog_highlight">

<ul class="calendar">
<li><a href="#">Nov</a></li>
<li><a href="#">25</a></li>
</ul>


<ul class="commentaries">
<li><a href="#">16</a></li>
</ul>


<div class="entry_info">

<div>
<a href="#"><img src="images/blog_pix_1.jpg" width="230" height="210" alt="" /></a>
</div>
<h2>Title</h2>

<p>Text</p>

<p><a href="#" class="read_more">Leer mas</a></p>

</div><!-- end entry info -->

</div><!-- end blog highlight -->
我对jQuery还相当陌生,尝试过兄弟姐妹和next以及其他方法,但都不管用。我尝试使用eq(0),它可以工作,但我如何循环它?我之所以选择类而不是ID,是因为这是一个重复多次的框


谢谢你的帮助。

为什么不直接使用CSS呢

ul.calendar:hover ~ .entry_info {
    // selects all .entry_info's which are on the same level (siblings) as the ul.calender  which is hovered over
}
顺便说一句,我确信jQuery的magic$-函数也支持通用同级组合器,因此
$(“item~sibling”)
应该可以正常工作:

$("...").hover(function() {
    $("... ~ siblings");
}
见:

  • (选择器CSS 3)
  • (支持CSS 1-3选择器)

它不起作用,因为
nextAll
基于选择器获取所有同级。你的超链接不是兄弟姐妹。相反,您可以使用
find
搜索链接的条目信息


它使用纯CSS实现了这一点。然后,我将使用~兄弟姐妹构建jQuery回退。非常感谢!!!这看起来很酷,但我无法让它在Chrome 15中工作。你能告诉我我做错了什么吗?你犯了和我一样的错误@当我把课程作为日历时,Scrawy打印了日历。我不知道哪一个是正确的英语,它不是我的第一语言,但我试着:)我想我为你编辑了小提琴。我对小提琴和钢琴有点陌生。谢谢你!你真的在添加/删除的类中设置了css规则吗
ul.calendar:hover ~ .entry_info {
    // selects all .entry_info's which are on the same level (siblings) as the ul.calender  which is hovered over
}
$("...").hover(function() {
    $("... ~ siblings");
}
<ul class="calendar">
    <li><a href="#">Nov</a></li>
    <li><a href="#">25</a></li>
</ul>
<div class="entry_info">
   <p><a href="#" class="read_more">Leer mas</a></p> <!-- NOT A SIBLING! -->
</div>
$('ul.calendar').hover (
    function () {    
        $(this).nextAll('.entry_info').addClass('hover_border');
        $(this).nextAll('.entry_info').find('a.read_more').addClass('more_jquery');
        $(this).next('ul.commentaries').addClass('bubble_hover');        
    },

    function () {    
        $(this).nextAll('div.entry_info').removeClass('hover_border');
        $(this).nextAll('.entry_info').find('a.read_more').removeClass('more_jquery');
        $(this).next('ul.commentaries').removeClass('bubble_hover');
});