I have a couple of elements that I want to change the grayscale of when hovering. Instead of changing all of them at the same time (since they have the same class) I only want to change the one that is currently being hovered.
So I made the following code:
tpj(".cftoverlay").hover(function(){
tpj(this).find(".hoverBorderWrapper > img").css("filter","grayscale(0%)");
console.log("test");
},function() {
tpj(this).find(".hoverBorderWrapper > img").css("filter","grayscale(100%)");
console.log("test1");
});
The console log works but for some reason the rest of the code doesn't. What am I doing wrong?
My html structure:
<span class="cftoverlay">
<img src="images/overlay.png">
</span>
<span class="hoverBorderWrapper">
<img width="750" height="350" src="cms/images/afbeeldingen/artikelen/IMG-20170208-WA0021.jpg" class="img-responsive big-featuredarticles" alt="css3panels-alt-04" title="css3panels-alt-04">
<span class="theHoverBorder"></span>
</span>
The image stays grayscale no matter what since I added some css so it's grayscale when not hovered, but inline css added by jquery should always overwrite that right?
When hovering it, I can see something changing in my element inspector on this line:
<span class="cftoverlay">
But no css is added anywhere.
tpj(".cftoverlay")do?.find()only searches through the descendants of.cftoverlay, so it will not find thehoverBorderWrapperspan, as that is a sibling and not a child/descendant.hoverBorderWrapperisn't a child of.cftoverlaythenfind()won't find anything. Also note that simply using a CSS rule :hover is faster and easier, no need JS here.