Forced to edit link instead of going to link in editable table cell

Forced to edit link instead of going to link in editable table cell

I have the following code which allows me to edit a cell, but the problem is that when I want to click on the link, it forces me to edit instead. I want to be able to edit only when I click on the pen icon, but I can't seem to figure out how to do it.


HTML


  1. <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">

  2. <table border="1" style="width:100px" style="height:99px" style="margin:0 
  3. auto">
  4. <tbody>
  5. <tr>
  6. <td ><div class="row_data" edit_type="click" col_name="datamapname"><i 
  7. class="fa fa-pencil"></i><a id="dm" href="https://www.google.com/" 
  8. target="_blank">Sample</a></div></td>

  9. </tr> 

  10. </tbody>
  11. </table>

Jquery

  1.     $(document).on('click', '.row_data', function(event) 
  2. {
  3.     //Remove pencil icon.
  4.     $(this).find('i.fa-pencil').remove();

  5.     //Remove link
  6.     $("#dm").removeAttr('href');

  7.     event.preventDefault(); 
  8.     if($(this).attr('edit_type') == 'button')
  9.     {
  10.         return false; 
  11.     }
  12.     //make div editable
  13.     $(this).closest('div').attr('contenteditable', 'true');
  14.     //add bg css
  15.     $(this).addClass('bg-warning').css('padding','5px');
  16.     $(this).focus();
  17.     $(this).attr('original_entry', $(this).html());
  18. })  
  19.     //--->make div editable > end

  20.   // --> save single field data > start
  21.     $(document).on('focusout', '.row_data', function(event) 
  22.     {
  23.         event.preventDefault();

  24.         if($(this).attr('edit_type') == 'button')
  25.         {
  26.             return false; 
  27.         }

  28.     //Add pencil icon back
  29.         $(this).append('<i class="fa fa-pencil"></i>');

  30.     //Add link back
  31.     $("#dm").attr('href','https://www.google.com/');

  32.     })  

JSFiddle: https://jsfiddle.net/89zgd1ry/