Can anyone change this jQuery code into Vanilla JS.
onmouseover on wrapper and card I am showing the card. and onmouseleave it’s again going display none.
<div class="wrapper" onmouseover="show(this);" onmouseleave="hide(this);"> <div class="box"></div> <div class="card" onmouseover="show(this);" onmouseleave="hide(this);"> <img src="img-2"> </div> </div> <div class="wrapper" onmouseover="show(this);" onmouseleave="hide(this);"> <div class="box"></div> <div class="card" onmouseover="show(this);" onmouseleave="hide(this);"> <img src="img-1"> </div> </div>
function show(e) { $(e).find('.card').css('display','block'); } function hide(e) { $(e).find('.card').css('display','none'); }
3
Answers
You must make these changes to your code:
You can also achieve the same effect using only CSS:
Following should do the trick
You can also do this with pure CSS:
JQuery’s find is a children selector (so you are looking for children of the actual element you are trying to select)
So depending on the element that you want triggerring the function,
But at the end of the day, just use CSS selectors: eg:
Also, I’m not 100% sure display: none and onMouse effects are compatible, you should try using opacity: 0 or something like that