hover
is not a Handler that the method on()
you understand. jQuery makes events available mouseenter
and mouseleave
. To make the developer’s life easier, there is the method hover()
. According to the documentation,
$( selector ).hover( handlerIn, handlerOut )
is an abbreviation of
$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );
You can write the method as follows:
$(".project").hover(function() {
$(this).find(".sendProposal").removeClass("hide");
}, function(){
$(this).find(".sendProposal").addClass("hide");
}
);
.project{
width: 200px;
height: 200px;
background-color: red;
}
.sendProposal{
width: 100px;
height: 100px;
background-color: green;
}
.hide{
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="project">
<div class="sendProposal hide"></div>
</div>
As I don’t know the structure of your CSS, I invented a few things just for the purpose of exemplification.
In this example, the way it is, there is still the possibility of using the method toggleClass()
, which makes the snippet more elegant. But since I don’t know exactly what you want to do, maybe he won’t answer. Anyway, follow the same example, using the quoted method.
$(".project").hover(function() {
$(".sendProposal", this).toggleClass("hide");
});
.project{
width: 200px;
height: 200px;
background-color: red;
}
.sendProposal{
width: 100px;
height: 100px;
background-color: green;
}
.hide{
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="project">
<div class="sendProposal hide"></div>
</div>
As a bonus, see how I built the selector in the second example, without using the method find()
. This is one more possibility that jQuery offers.
You could still use the pseudo-selector ::hover
, and not depend on the JS, but there is another story...
class . project is class . sendProposal ? You also have to see if the project class is getting Hover, it might be Hidden or there might be some size or display problem.
– Pedro Morais
@Pedromorais class . project is Parent class . sendProposal !! Also occurs the event when I put only 1 Function, then the class . project is receiving the event.
– Marcos Vinicius