Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Created November 13, 2015 07:14
Show Gist options
  • Save Archie22is/4c23d568e163161a17c7 to your computer and use it in GitHub Desktop.
Save Archie22is/4c23d568e163161a17c7 to your computer and use it in GitHub Desktop.
jQuery hover – replace div with another div
<!-- HTML -->
<div class="switch">
<div class="avg_words float_left">
A+ (hover to see score)
</div>
<div class="avg_num">
AVG = 98.35%
</div>
</div>
<div class="switch">
<div class="avg_words float_left">
A+ (hover to see score)
</div>
<div class="avg_num">
AVG = 98.35%
</div>
</div>
<div class="switch">
<div class="avg_words float_left">
A+ (hover to see score)
</div>
<div class="avg_num">
AVG = 98.35%
</div>
</div>
<!-- Style -->
<style>
.switch {
border: 1px solid red;
}
.avg_num {
display: none;
}
</style>
<!-- jQuery -->
<script>
$('.switch').hover(function() {
$(this).find('.avg_words').hide();
$(this).find('.avg_num').show();
}, function() {
$(this).find('.avg_num').hide();
$(this).find('.avg_words').show();
});
</script>
<!-- NOTES: The script should be easy to follow. Questions, tweet me: @aatsol -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment