Mouseover effect td with jquery or css

3

How can I make when I hover over my td , display the edit icon in it?

Note: My code does not work:

jQuery Event:

$(".editableSpan").mouseover(function(){
    $("#tdEditable").append("<span id='widthSource'></span><span class='glyphicon glyphicon-pencil'></span>");
});

HTML:

<td id="tdEditable" class="editableSpan"><span id="widthSource"></span></td>

I would like that when the event is hover on any td in my table it shows the edit icon aligned to the right.

    
asked by anonymous 08.10.2015 / 21:48

1 answer

3

See if it does.

$( "td" ).hover(
  function() {
    $( this ).append( $( "<i class='fa fa-pencil'></i>" ) );
  }, function() {
    $( this ).find( ".fa" ).remove();
  }
);
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
.fa{
   float: right;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<table style="width:50%">
  <tr>
    <td>Jill</td>
  </tr>
  <tr>
    <td>Eve</td>
  </tr>
  <tr>
    <td>John</td>
  </tr>
</table>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    
08.10.2015 / 22:04