JavaScript Change one element on hover another change hover element,change element on hover css,change child

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?

Answer:1

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')
})

JSFIDDLE

Answer:2

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");
});
Answer:3

Code

 $("#menu-item993").mouseenter(function () {
     $(".post-filter").addClass('dispaly')
 }).mouseleave(function () {
     $(".post-filter").removeClass('dispaly');

});

Css

   .display
    {
     display:block;
   }
Answer:4

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

Answer:5

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>
Answer:6

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>
Answer:7

I'm calling js function every 2 seconds where on certain condition I want to update div on the view. <div id="ball_{{ballIndex}}">{{ball}}</div> on ng controller var myCounter = ...

I'm calling js function every 2 seconds where on certain condition I want to update div on the view. <div id="ball_{{ballIndex}}">{{ball}}</div> on ng controller var myCounter = ...

My function below returns an object containing the sorted playerPoints passed in via the "array of objects" parameter. Without modifying the passed in array, is there a more efficient/performant way ...

My function below returns an object containing the sorted playerPoints passed in via the "array of objects" parameter. Without modifying the passed in array, is there a more efficient/performant way ...

I tried in my chrome debug console: >function m(){function toString(){return "abc"}} undefined >new m().toString() "[object Object]" I expect it to print "abc". Why?

I tried in my chrome debug console: >function m(){function toString(){return "abc"}} undefined >new m().toString() "[object Object]" I expect it to print "abc". Why?

I'm trying to implement automatic formatting to an web-page. So that when you type 12345678, it is automatically €123.456,78. <div class="form-group"> <input type="text" required class=...

I'm trying to implement automatic formatting to an web-page. So that when you type 12345678, it is automatically €123.456,78. <div class="form-group"> <input type="text" required class=...