カーソルを合わせたときに、ある div を別の div に置き換えたい。具体的には、「苦労している」や「期待を超えている」などの単語の平均があり、ユーザーが単語の平均にカーソルを合わせたときに、これを数値の平均に置き換えたいと考えています。
#html
<div class="switch avg_words float_left">
A+ (hover to see score)
</div>
<div class="avg_num">
AVG = 98.35%
</div>
#css
.avg_num {
display: none;
}
#jquery
$('.switch').hover(function() {
$(this).closest('.avg_words').hide();
$(this).next('div').closest('.avg_num').show();
}, function() {
$(this).next('div').closest('.avg_num').hide();
$(this).closest('.avg_words').show();
});
最初の div を非表示にして 2 番目の div に置き換えるのは簡単ですが、ホバーが終了したときに通常の状態に戻すコードに問題があります。ホバーすると、 がdiv
交互に点滅します。