-7

the whole text to be selected on click in jQuery

  <tr>
  <td class="wt" type="text" contenteditable="true" align="right">0.00</td>
  </tr>
arthi v
  • 3
  • 1
  • 3
  • Welcome to Stack Overflow! Please read [what this site is about](https://stackoverflow.com/about) and "[How to ask](https://stackoverflow.com/questions/how-to-ask)" before asking a question. – j08691 Aug 21 '17 at 13:52
  • Possible duplicate of [select all text in contenteditable div when it focus/click](https://stackoverflow.com/questions/3805852/select-all-text-in-contenteditable-div-when-it-focus-click) – node_modules Aug 21 '17 at 13:53
  • yes i have tried select – arthi v Aug 21 '17 at 13:54
  • $(".wt[type=text]").click(function() { $(this).select(); }); – arthi v Aug 21 '17 at 13:54

1 Answers1

0

Hope this helps:

$('#selectAll').on('focus', function() {
  var cell = this;
  var range, selection;
  if (document.body.createTextRange) {
    range = document.body.createTextRange();
    range.moveToElementText(cell);
    range.select();
  } else if (window.getSelection) {
    selection = window.getSelection();
    range = document.createRange();
    range.selectNodeContents(cell);
    selection.removeAllRanges();
    selection.addRange(range);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
  <td><div id="selectAll" contenteditable="true">0.00</div></td>
</tr>
Jegadesh B S
  • 689
  • 1
  • 6
  • 14