Reputation: 35
Hello I have the following HTML
<div id="sort_icons">
<img src="resources/images/sort_book.png" class="sort_icons" id="book">
</div>
<div id="sorter_text">
<p>I DO
<span class="sorter_hidden" id="sorter_bd">BOOK DESIGN.</span>
</p>
</div>
and the CSS is the following
.sorter_hidden{
display: none;
}
.sorter_show{
display: inline;
}
and this is the query, I want that whenever you hover over image #book, the text in span #sorter_bd displays (it is hidden at first) I can't seem to make it work, any ideas?
$( document ).ready(function () {
$("#book").hover(function() {
$("#sorter_bd").removeClass("sorter_hidden");
/*$("#sorter_bd, #sorter_ph, #sorter_id, #sorter_dv, #sorter_st, #sorter_ev").css("display","none");*/
$("#sorter_bd").addClass("sorter_show");
});
});
Upvotes: 1
Views: 648
Reputation: 38112
You can use hover() with two handlers like this:
$( "#book" ).hover(
function() {
$("#sorter_bd").addClass("sorter_show");
}, function() {
$("#sorter_bd").removeClass("sorter_show").addClass("sorter_hidden");
}
);
or you can just use toggleClass() here:
$("#book").hover(function() {
$("#sorter_bd").toggleClass('sorter_hidden sorter_show');
});
Upvotes: 2
Reputation: 15112
Use .toggleClass()
instead of add and remove separately.
$("#book").hover(function() {
$("#sorter_bd").toggleClass('sorter_show sorter_hidden');
});
Upvotes: 2