2

box div will be hidden during pageload, when we hover on it it should display, onmouseover it should display, and onmouseout it should be hidden. can any body suggest me how to do in jquery, i am beginner in Jquery :)

Update this Div is placed in ItemTemplate of gridview. will it be worked ? with answeered which you people provide ?

<div id="box" style="display: none">
   <a href="#" class="bt btleft">Highlight it</a>
   <a href="#" class="bt btright">Reset</a>
</div>
Ravi Gadag
  • 15,735
  • 5
  • 57
  • 83
  • 1
    how would you define it being "over" it if its hidden, hidden elements have no visible area to be over. – j_mcnally Feb 21 '12 at 05:33
  • Can't hover on what's not there. You need another trigger if the div is hidden. – Scott Feb 21 '12 at 05:35
  • well you can if you are using visibility property of CSS rather than display:none. visibility holds on to the space. Check my jsfiddle from my answer. Cheers! – Jaspreet Chahal Feb 21 '12 at 05:44

5 Answers5

7

you are better off using visible property in CSS rather than display:none to start with because display:none will sort of remove the space of the container itself.

try this out

http://jsfiddle.net/sfUHn/7/

Your HTML should look like this

<div id='container'>
 <div id="box" style="visibility: hidden">
 <a href="#" class="bt btleft">Highlight it</a>
 <a href="#" class="bt btright">Reset</a>
 </div>
</div>​

You jquery will look like this

 $("#container").hover(function () {
$("#container div").css("visibility","visible");
  },
  function () {
    $("#container div").css("visibility","hidden");
  });​

Hope this helps

Jaspreet Chahal
  • 2,759
  • 1
  • 15
  • 17
1

modify the html a bit like

<div id="hover">hover</div>
<div id="box" style="display: none">
   <a href="#" class="bt btleft">Highlight it</a>
   <a href="#" class="bt btright">Reset</a>
</div>

jquery part

$("#hover").hover(function(){
  $("#box").slideDown();

},function(){
     $("#box").slideUp(); 
});

DEMO

JIA
  • 1,485
  • 13
  • 11
  • can you check the updated question, acutally i have placed div in itemtemplate of gridview – Ravi Gadag Feb 21 '12 at 05:48
  • where ever it is placed you need to define the hover event handler that is visible like in my answer i have attached it to the visible div similarly you can attach the handler to some visible element of your grid – JIA Feb 21 '12 at 05:51
1

wrap it in another div and bind a mouseover event on that div

<div id='parent-wrapper'>
  <div id="box" style="display: none">
     <a href="#" class="bt btleft">Highlight it</a>
     <a href="#" class="bt btright">Reset</a>
  </div>
</div>

$('#parent-wrapper')
 .mouseover( 
   function() {
    $('#box').show();
   } 
 );
Shaheer
  • 2,105
  • 4
  • 25
  • 39
1

Try this, the simplest one..

$("#box").hover(function()
{
  $(this).show();
},
function()
{
  $(this).hide();
});
Akhil Thayyil
  • 9,263
  • 6
  • 34
  • 48
0

Wrap the div with another div and add the code to that wrapped div:

$('#wrapper').bind('mouseover hover', function(){

     $('#box').show();

});


$('#wrapper').mouseout(funcion(){

    $('#box').hide();

});
Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193
  • As per other answers, the div is hidden. Can't hover over it. Also, is "mouseover hover" a good way to bind? Why not just use the .hover() (which encapsulates mouseenter and mouseleave) or at least use parralel binding types. – Greg Pettit Feb 21 '12 at 05:42