Reputation: 399
I've got following piece of html code:
<div class="header-menu hide-for-small">
<ul id="primary-menu" class="subtext">
<li id="menu-item-993"><a>X</a></li>
<li id="menu-item-994"><a>Y</a></li>
<li id="menu-item-995"><a>Z</a></li>
</ul>
</div>
<div class="post-filter">..</div>
Plus the css:
.post-filter {
display: none!important;
}
What I'm trying to achieve is to show .post-filter
div only when hovered #menu-item-993
. So im doing:
#menu-item-993:hover .post-filter {
display:block!important;
}
But this just don't work. I've tried to put +
or ~
between ..:hover
and .post-filter
- without success. What Im doing wrong?
Upvotes: 2
Views: 6101
Reputation: 2211
<a id="thumbnail" href="#"><img src="http://dummyimage.com/150x150/0066ff/fff"></a>
<div id="title">filename.jpg</div>
#thumbnail {
display: block;
width: 150px;
height: 150px;
}
#thumbnail:hover + #title {
display: block;
}
#title {
display: none;
color: #ffffff;
background-color: #000000;
text-align: center;
width: 130px;
padding: 10px;
}
Upvotes: 0
Reputation: 6628
Try this toggleClass option
$("body").on("mouseover mouseout", '#menu-item-993', function(){
$('.post-filter').toggleClass("show hide");
});
.post-filter {
display: none!important;
}
.show
{
display: block!important;
}
.hide
{
display: hide!important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="header-menu hide-for-small">
<ul id="primary-menu" class="subtext">
<li id="menu-item-993"><a>X</a>
</li>
<li id="menu-item-994"><a>Y</a>
</li>
<li id="menu-item-995"><a>Z</a>
</li>
</ul>
</div>
<div class="post-filter">text</div>
Upvotes: 1
Reputation: 10746
Here is a way using hover
function and the show
/hide
functions
$('#menu-item-993').hover(function(){
$('.post-filter').show();
},function(){
$('.post-filter').hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="header-menu hide-for-small">
<ul id="primary-menu" class="subtext">
<li id="menu-item-993"><a>X</a>
</li>
<li id="menu-item-994"><a>Y</a>
</li>
<li id="menu-item-995"><a>Z</a>
</li>
</ul>
</div>
<div class="post-filter" style="display:none">..</div>
Upvotes: 1
Reputation: 7884
Here's a mouseover (mouseenter) function:
$("#menu-item-993").mouseenter(function () {
$(".post-filter").show();
}).mouseleave(function () {
$(".post-filter").hide();
});
If this doesn't override the !important try this (assuming no other dependencies in JS on post-filter class):
$("#menu-item-993").mouseenter(function () {
$("div.header-menu + div").removeClass("post-filter");
}).mouseleave(function () {
$("div.header-menu + div").addClass("post-filter");
});
Upvotes: 2
Reputation: 50291
You can use hover
function & add css
to show and hide it
$("#menu-item-993").hover(function(){
$(".post-filter").css('display','block')
},function(){
$(".post-filter").css('display','none')
})
Upvotes: 0
Reputation: 2776
Add and remove the class of styling with Javascript. And you don't need !important
on the initial css.
$("#menu-item-993").mouseenter(function(){
$(".post-filter").addClass("showit");
}).mouseleave(function(){
$(".post-filter").removeClass("showit");
});
See my JSFIDDLE
Upvotes: 1
Reputation: 1288
$("#menu-item993").mouseenter(function () {
$(".post-filter").addClass('dispaly')
}).mouseleave(function () {
$(".post-filter").removeClass('dispaly');
});
.display
{
display:block;
}
Upvotes: 1