1

I would like to show and hide a section which is landing over a div as a second screen when i hover one the section i want it to hide and show here's what I've done lately. I have tried a lot of things but nothing works.

<div class=" banner">

    <div class="section-left">
        <section class="ha">
            <p> الوافد الجديد</p>
            <a href="#"><h6> تسوق الان</h6></a>
        </section>

    </div>

    <div class="section-mid">
        <section>

            <p> الوافد الجديد</p>
            <a href="#"><h6> تسوق الان</h6></a>
        </section>
    </div>

    <div class="section-right">
        <section>
            <p> الوافد الجديد</p>
            <a href="#"><h6> تسوق الان</h6></a>
        </section>

    </div>
.section-left {
    background-image: url("img/Layer-44.jpg");
    z-index: 99999;
    position: absolute;
    display: inline-block;
    left: 90px;
    width: 309px;
    height: 180px;
}
.ha {
    background-color:rgba(187,166,153,.6);
    width: 100%;
    height:100%;
    display: none;
}
.section-left p {
    text-align: center;
    font-family: Droid Arabic Kufi;
    color: #fff;
    font-size: 18px;
    padding-top: 60px;
    position: relative;
}
.section-left p:after{
    background-image: url("img/lin.png");
    display: block;
    content: " ";
    margin-left: 130px;
    margin-top: 15px;
    background-color: red;
    width: 64px;
    height: 1px;
}
.section-left h6{
    text-align: center;
    font-family: Droid Arabic Kufi;
    color: #fff;
    font-size: 18px;
    position: absolute;
    top: 110px;
    left: 110px;
}
$(function() {
    $(".section-left").hover(function() {
        $(this).has(".ha").show();
    }, function() {
        $(this).has(".ha").hide();
    });
});
5
  • you can use .toggle() Commented May 9, 2016 at 9:27
  • can you add your code in jsfiddle? Commented May 9, 2016 at 9:28
  • Have you added class ha to the section? Pls create a fiddle for this. Will be easier to help Commented May 9, 2016 at 9:30
  • has() returns a boolean. Presumably you want to use find() instead, although your HTML shown doesn't seem to match up with the JS code you posted Commented May 9, 2016 at 9:31
  • Its simple hover, you don't even need to use jQuery or JavaScript in there. Commented May 9, 2016 at 9:54

4 Answers 4

1
$(document).ready(function() {
$("#abc").hide();

$('#xyz').click(function() {
   $("#abc").show();
   $("#xyz").hide();
});

$('#xyz').click(function() {
    $("#abc").show();
    $("#xyz").hide();
});
});
Sign up to request clarification or add additional context in comments.

2 Comments

How does this help the OP?
But they are not the buttons the OP is using and he clearly already knows about the hide() and show()` methods as he's using them.
0
$(".section-left").mouseenter(function(){
$(".section-left").hide();
});
$(".section-left").mouseleave(function(){
$(".section-left").show();
});

This might help.

Comments

0

The main problem is because the has() method returns a boolean which is then throwing an error as you call show() or hide() on it. Instead, use find() which will return a jQuery object containing the .ha element. Also note that you can use the toggle() method in a single hover event handler over hide()/show() in separate functions. Something like this:

$(function() {
  $(".section-left").hover(function() {
    $(this).find(".ha").toggle();
  });
});
.section-left {
    background-image: url("img/Layer-44.jpg");
    z-index: 99999;
    position: absolute;
    display: inline-block;
    left: 90px;
    width: 309px;
    height: 180px;
}
.ha {
    background-color:rgba(187,166,153,.6);
    width: 100%;
    height:100%;
    display: none;
}
.section-left p {
    text-align: center;
    font-family: Droid Arabic Kufi;
    color: #fff;
    font-size: 18px;
    padding-top: 60px;
    position: relative;
}
.section-left p:after{
    background-image: url("img/lin.png");
    display: block;
    content: " ";
    margin-left: 130px;
    margin-top: 15px;
    background-color: red;
    width: 64px;
    height: 1px;
}
.section-left h6{
    text-align: center;
    font-family: Droid Arabic Kufi;
    color: #fff;
    font-size: 18px;
    position: absolute;
    top: 110px;
    left: 110px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="banner">
  <div class="section-left">
    <section class="ha">
      <p>الوافد الجديد</p>
      <a href="#"><h6> تسوق الان</h6></a>
    </section>
  </div>
  <div class="section-mid">
    <section>
      <p>الوافد الجديد</p>
      <a href="#"><h6> تسوق الان</h6></a>
    </section>
  </div>
  <div class="section-right">
    <section>
      <p>الوافد الجديد</p>
      <a href="#"><h6> تسوق الان</h6></a>
    </section>
  </div>
</div>

Comments

0

Why use JavaScript when you dont have too?

HTML:

<div id="hovering">
<div id="disappearing">

</div>
</div>

Style:

#hovering {
  width: 200px;
  height: 200px;
  background-color: red;
}
#disappearing {
  width: 100px;
  height: 100px;
  background-color: green;
}
#hovering:hover #disappearing {
  display: none;
}

https://jsfiddle.net/ww6rywdd/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.