<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"><script>
<script>
$(document).ready(function()
{
$('.sss').filter(':nth-child(n+2)').hide();
$('.sss').on('mouseenter', '.question', function()
{
$(this).next().slideDown(200).siblings('.answer').slideUp(200);
});
});
</script>
</head>
<div class="sss">
<div class="question">Question</div>
<div class="answer">Answer</div>
<div class="question">Question</div>
<div class="answer">Answer</div>
<div class="question">Question</div>
<div class="answer">Answer</div>
<div class="question">Question</div>
<div class="answer">Answer</div>
</div>
答案 0 :(得分:2)
试试这个:
$('.sss').children().filter(':nth-child(n+2)').hide();
如果您需要所有question
div,请尝试:
$('.sss').children(':nth-child(2n)').hide();
或强> 的
$('.sss .question').hide();
并且适用于所有answer
:
$('.sss').children(':nth-child(2n+1)').hide();
或强> 的
$('.sss .answer').hide();
答案 1 :(得分:0)
以下是不使用过滤器的替代方法:
$('.sss').children(':nth-child(n+2)').hide();