Search code examples
phpjqueryvisibilityfadeout

Visibility property not working properly with fadeOut()


I am developing a feedback page in a table with 3 columns.

Name         Feedback icons          status
-------------------------------------------------
Name1        icon1 icon2 icon3       Saved
Name2        icon1 icon2 icon3       Saved
-------------------------- and so on....

Initially the 3rd column is having css property visibility:hidden. On clicking any of the icon the 3rd column of that row need to show as 'Saved' and then disappear. Its working for me on the first time, i.e. if I am clicking icon2 on first time in the first row, saved will show and disappear, when I click icon1 on the same row, it will not show the 3rd column.

When I click the next row, the 3rd column will come only on first click. Please help me.

Html

<table class="tbl_result">
   <tbody>
    <tr><td width="55%">Nahed </td>
       <td width="42%">
         <div id="tbl_row_icons0" class="tbl_row_icons">
          <div class="emoji_parent">
           <div class="emoji_2 emojichild">
            <a title="Poor" class="feedbck_name" href="#"><img src="/user_uploads/my.aisc.ac.cy/emoticon/poor.png"></a>
           </div>
         <!--second icon--!>
          <div class="emoji_3 emojichild"><a title="Good" class="feedbck_name" href="#"><img src="/user_uploads/my.aisc.ac.cy/emoticon/good.png"></a>
         </div>
       </div>
      </td><td width="7%" class="toggle_save">Saved</td>
   </tr>
  </tbody>
 </table>

CSS

.toggle_save
{
    visibility:hidden;
    color:green;
    font-weight: bold;
}

Jquery function

//click event for icon 
$(".feedbck_name").click(function()
{    
   $(this)
       .closest('td')
       .next('td.toggle_save')
       .css('visibility','visible')
       .delay(1000)
       .fadeOut();

   return false;
});

Solution

  • As you are doing fadeOut() your script will make it display:none in css property. You need to fade on visibility instead. Try below code for the same

    $(".feedbck_name").click(function()
    {    
       $(this).parent('td').siblings('td.toggle_save')
        .css('opacity','1')
        .css("visibility", "visible")
        .fadeTo(1500, 0, function(){
             $(this).parent('td').siblings('td.toggle_save')
             .css("visibility", "hidden").css('opacity','1');   
        });
        return false;
    });
    

    Check this fiddle for the same