1

I am trying to make a div that you can hover the mouse over, and another one will appear. This is what I have so far...

html

<div id="buttons">
<div id="box"></div>
<div id="content">content here</div>
</div>

css

#box {
position:absolute;
width: 10vw;
height: 10vw;
background-color: blue;
}

#content {
position:absolute;
width: 10vw;
height: 10vw;
background-color: red;
visibility: hidden;
}

jquery

$( "box" )
.mouseover(function() {
$( "content").style.visibility( "visible" );
})

any help you be much appreciated. Thanks!

5 Answers5

1

You are mixing up JQuery with pure javascript in many places...

Either do this in JQuery:

$("#box").mouseover(function() {
    $("#content").css("visibility", "visible");
});

or do this in pure javascript:

document.getElementById("box").onmouseover = function() {
    document.getElementById("content").style.visibility = "visible";
};

But you can achieve the same effect using css only:

#box {
  position:absolute;
  width: 10vw;
  height: 10vw;
  background-color: blue;
}

#content {
  position:absolute;
  width: 10vw;
  height: 10vw;
  background-color: red;
  visibility: hidden;
}

#box:hover + #content {
  pointer-events: none;
  visibility: visible;
}
<div id="buttons">
  <div id="box"></div>
  <div id="content">content here</div>
</div>
LcSalazar
  • 16,524
  • 3
  • 37
  • 69
1

You could use:

('#box').hover(
  function () {
    $('#content').show(); //or css('visibility','visible');
  }, 
  function () {
    $('#content').hide(); //or css('visibility','hidden');
  }
);

This will show/hide the div. You miss the '#'

JP. Aulet
  • 4,375
  • 4
  • 26
  • 39
0

See the working fiddle here : https://jsfiddle.net/8dpcuztk/

Here, Instead of visibility attribute, play with display : none.

So in essence, you will use show and hide functionality for the second div.

Also, your selector are not working because you are searching for Id and must use # in front of div id.

$("#box").on("mouseover", function() {
    $("#content").show();
})
Ash
  • 2,575
  • 2
  • 19
  • 27
0

Use jQuery append.

$("#box").on('mouseenter', function() {
 $("#content").append("<div class='box'></div>");
});

https://jsfiddle.net/32eckm71/40/

Ryan Dantzler
  • 1,124
  • 1
  • 8
  • 18
0

$( "#box" ).hover(
  function() {
    $( "#content" ).fadeIn(); //.show();
  },
  function(){
    $("#content").fadeOut(); //hide();
  }
);
#buttons{position:relative;}
#box {
position:absolute;top:0;left:0;width:10vw;height:10vw;background-color:blue;cursor:pointer;
}

#content {
position:absolute;top:100px;left:100px;width:10vw;height:10vw;background-color:red;
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="buttons">
  <div id="box"></div>
  <div id="content">content here</div>
</div>
cssyphus
  • 37,875
  • 18
  • 96
  • 111