I have three boxes across and one line of text below that changes the text based on which box is hovered over. HTML
<div style="display:inline-block;">
<div id="box1" class="outerbox">
</div>
<div id="box2" class="outerbox">
</div>
<div id="box3" class="outerbox">
</div>
</div>
<div style="display:block;">
<p id="p1">
Paragraph 1
</p>
<p id="p2">
Paragraph 2
</p>
<p id="p3">
Paragraph 3
</p>
</div>
and I am running this script with it, which seems amateurishly repetitive.
$(document).ready(function() {
$("#box1").hover(function() {
$("#p1").addClass("show");
}, function() {
$("#p1").removeClass("show");
});
$("#box2").hover(function() {
$("#p2").addClass("show");
}, function() {
$("#p2").removeClass("show");
});
$("#box3").hover(function() {
$("#p3").addClass("show");
}, function() {
$("#p3").removeClass("show");
});
});
How would I better code the script to do the same function. Thanks. FIDDLE