javascript - Hide input box once click to other element or mouseup but retain once focus -


how hide input box once mouseup or click other element , retain once focus? current code below, mouseup working thing once focus on showed input boxes, they're being hidden immediately. see demonstration below , click edit button. input boxes show, disappear once focused.

$(".edit").click(function () {        var $span = $(this);      $(this).closest('tr').find('.textdisplay').hide();      $(this).closest('tr').find('.editbox').css("display", "inline");        var id = $(this).attr('id');      var removeidedit = id.replace('edit_', '');      $(this).hide();      $("#save_" + removeidedit).css("display", "inline");    });    $(".save").click(function () {        var $span = $(this);      $(this).closest('tr').find('.textdisplay').css("display", "inline");        $(this).closest('tr').find('.editbox').hide();        var id = $(this).attr("id");      var removeidsave = id.replace('save_', '');      $(this).hide()      $("#edit_" + removeidsave).css("display", "inline");    });    $(document).mouseup(function () {      $(".editbox").hide();      $(".textdisplay").show();      $(".edit").css("display", "inline");      $(".save").css("display", "none")  });
.save {      display: none;  }  table {      width: 400px;  }  }  table td {      border: 1px solid;  }  .trash {      font-size: 14px;      padding-left: 5px;  }  .save, .edit {      padding-left: 5px;      position: absolute;      font-size: 14px;  }  .editbox {      font-size:14px;      display: none;  }  .textdisplay {      font-size: 14px;      float: left;      font-weight: normal;      word-wrap:break-word;      white-space: normal;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>  <table>      <tr>          <td> <span class="textdisplay"> data 1a </span>              <input type="text" class="editbox" value="data 1a" />          </td>          <td> <span class="textdisplay"> data 1b </span>              <input type="text" class="editbox" value="data 1b" />          </td>          <td>              <a href="#" id="282" class="trash">delete</a>              <a href="#" id="edit_282" class="edit">edit</a>               <a href="#" id="save_282" class="save">save</a>          </td>      </tr>      <tr>          <td>              <span class="textdisplay"> data 2a </span>              <input type="text" class="editbox" value="data 2a" />          </td>          <td>              <span class="textdisplay"> data 2b </span>              <input type="text" class="editbox" value="data 2b" />          </td>          <td>              <a href="#" id="283" class="trash">delete</a>              <a href="#" id="edit_283" class="edit">edit</a>               <a href="#" id="save_283" class="save">save</a>          </td>      </tr>  </table>

js fiddle

so change mouseup following code:

$(document).mouseup(function(e){     if ($(e.target).hasclass('editbox')) return false;     $(".editbox").hide();     $(".textdisplay").show();     $(".edit").css("display","inline");     $(".save").css("display","none") });      

as in fiddle:

https://jsfiddle.net/l6v2880z/7/

edit: sorry $(this) wrong context used before...


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -