-1

The div is not changing properties when I hover on the <input> of that div. It doesn't seem to work.

I want to hover over myclass div inputs and make myclass2 div visible. How to do that ?

.myclass #that:hover+.myclass2 #this {
  left: 100px;
}
<div class="myclass" id="that">
  <input class="logout1" type="button" value="All" id="myBtn"></input>
  <input class="logout2" type="button" value="Section Wise" id="myBtn1"></input>
  <span class="first"></span>
  <span class="second"></span>
</div>
<div class="myclass2" id="this">
  <input class="logout3" type="button" value="Section1" id="myBtn2"></input>
  <input class="logout4" type="button" value="Section2" id="myBtn3"></input>
  <input class="logout5" type="button" value="Section3" id="myBtn4"></input>
  <input class="logout6" type="button" value="Section4" id="myBtn5"></input>
  <span class="third"></span>
  <span class="fourth"></span>
</div>
matthias_h
  • 11,162
  • 9
  • 19
  • 38

4 Answers4

3

.myclass2{
  display:none;
}

.myclass:hover+.myclass2{
  display:block;
}
<div class="myclass" id="that">
  <input class="logout1" type="button" value="All" id="myBtn">
  <input class="logout2" type="button" value="Section Wise" id="myBtn1"></input>
  <span class="first"></span>
  <span class="second"></span>
</div>
<div class="myclass2" id="this">
  <input class="logout3" type="button" value="Section1" id="myBtn2">
  <input class="logout4" type="button" value="Section2" id="myBtn3">
  <input class="logout5" type="button" value="Section3" id="myBtn4"
  <input class="logout6" type="button" value="Section4" id="myBtn5">
  <span class="third"></span>
  <span class="fourth"></span>
</div>
Yasaman.Mansouri
  • 550
  • 1
  • 3
  • 12
0

This works - you need position

HOWEVER you cannot click the new buttons - so see second example

#this { position:absolute; width: 300px }

#that:hover + #this {
  right: 100px
}
<div class="myclass" id="that">
  <input class="logout1" type="button" value="All" id="myBtn" />
  <input class="logout2" type="button" value="Section Wise" id="myBtn1" />
  <span class="first">First</span>
  <span class="second">Second</span>
</div>
<div class="myclass2" id="this">
  <input class="logout3" type="button" value="Section1" id="myBtn2" />
  <input class="logout4" type="button" value="Section2" id="myBtn3" />
  <input class="logout5" type="button" value="Section3" id="myBtn4" />
  <input class="logout6" type="button" value="Section4" id="myBtn5" />
  <span class="third">Third</span>
  <span class="fourth">Fourth</span>
</div>

I THINK you mean this:

/* 
$("#myBtn").on("click",function() {
  $("#this").toggle()
})
*/

$("#myBtn").on("mouseenter",function() {
  $("#this").show();
})
$("#myBtn").on("mouseleave",function() {
  setTimeout(function() { $("#this").hide(); },3000);
})
#this { display:none }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="myclass" id="that">
  <input class="logout1" type="button" value="All" id="myBtn" />
  <input class="logout2" type="button" value="Section Wise" id="myBtn1" />
  <span class="first">First</span>
  <span class="second">Second</span>
</div>
<div class="myclass2" id="this">
  <input class="logout3" type="button" value="Section1" id="myBtn2" />
  <input class="logout4" type="button" value="Section2" id="myBtn3" />
  <input class="logout5" type="button" value="Section3" id="myBtn4" />
  <input class="logout6" type="button" value="Section4" id="myBtn5" />
  <span class="third">Third</span>
  <span class="fourth">Fourth</span>
</div>
mplungjan
  • 134,906
  • 25
  • 152
  • 209
  • 1
    The `` tag does not use and does not need a closing slash and never has in HTML. – Rob Apr 28 '20 at 09:30
  • This isn't XHTML. But we've had this conversation before. – Rob Apr 28 '20 at 09:36
  • I very much prefer to write my markup the way the HTML specification is written by the browser vendors and not by the opinion of someone on Stack Overflow. – Rob Apr 28 '20 at 09:38
  • I am betting you never use XML on any web page or you aren't properly serving it as XHTML. In any case, the closing slash is pure nonsense in HTML as the specification will tell you if you read it. – Rob Apr 28 '20 at 09:43
0

If you just wan't to make your that div visible when you hover this. Then you can use visibile properties, can be managed with css or jquery method.

Css method

#that:hover + #this{
    visibility : visible;
}

#this{
    visibility : hidden;
}

Jquery method

Something like :

$('#this').hide();
$('#that').hover(function(event){
   $('#this').show();
});
jlegius
  • 18
  • 4
0

I would remove the classes or the ids (or keep them if you need them for something else...) however here is an SCSS that can solve this issue for you:

Here, I removed the classes, but as I mentioned above, you can keep the classes and remove the Ids or keep them both :)

#this {
    display: none;
}

#that {
    &:hover {
        + {
            #this {
                display: block;
            }
        }
    }
}
Eden Sharvit
  • 424
  • 5
  • 12