user3147424
user3147424

Reputation: 3662

Show and hide table row on hover, initially hidden, not hidden if input

I have an HTML table with a row that has an input. When I hover over the row, I want to expand the row and show the input and then collapse if not hovered. However, I want the row to start of collapsed and I do not want the row to collapse if there is a value in the input.

Here is a fiddle:

http://jsfiddle.net/4Hdge/

<table style="width:300px; background-color:#d3d3d3">
 <tr id="filter" style="background-color:blue">
  <td><input id="search" placeholder="Search" style="width:100px"/></td>
  <td></td> 
  <td></td>
 </tr>
 <tr>
  <td>Jill</td>
  <td>Smith</td> 
  <td>50</td>
 </tr>
 <tr>
  <td>Eve</td>
  <td>Jackson</td> 
  <td>94</td>
 </tr>
</table>


$("#filter").hover(

function () {

        $("#search").show();

  },
function () {

        $("#search").hide();

  }
);

Upvotes: 0

Views: 1755

Answers (4)

Kiran
Kiran

Reputation: 1798

I would say the correct answer is a combination of the two answers given :)

//var tableRow = $("#search").parent().parent();
$("#search").hide(); /*hide the search input initially*/
$("#filter").hover(
  function () {
    $("#search").show();
  },
  function () {
    if($("#search").val().trim() == "") //only hide the search box is empty
       $("#search").hide();
  }
);

EDIT

$("#search").hide(); /*hide the search input initially*/
$("#filter").hover(
  function () {
    $("#search").slideToggle();
  },
  function () {
    if($("#search").val().trim() == "") //only hide the search box if it is empty
       $("#search").slideToggle();
  }
);

Upvotes: 1

AtanuCSE
AtanuCSE

Reputation: 8940

JSFiddle

$("#search").hide();

$("#filter").hover(

    function () {

            $("#search").show();

    },
    function () {
        if($('#search').val()=="")
        $("#search").hide();


    }
);

Upvotes: 2

Ani
Ani

Reputation: 4523

Here you go: http://jsfiddle.net/4Hdge/7/

$("#search").hide();

$(".filter").mouseenter (function () {

        $("#search").show();

});
$('.filter').mouseleave(function () {

    $("#search").hide();

});

Upvotes: 1

Adesh Pandey
Adesh Pandey

Reputation: 769

why don't you just add if condition before hiding search?

if($("#search").val()=="") $("#search").hide();

Upvotes: -1

Related Questions