0

I am trying to highlight the text inside a div / span automatically when the page loads.

I am able to highlight text in a read-only textbox but, the text inside a div / span, is not working.

I am using typescript in my application.

Fiddler: http://jsfiddle.net/5zWad/75/

HTML:

<input type="text" readonly="readonly" value="ABC" />
<div>
  <span>
    this is a span
  </span>
</div>
<div>
  this is a div
</div>

JS Inside a typescript method,

//WORKING
$('input').select();

//NOT WORKING
$('span').select();

//NOT WORKING
$('div').select();

I looking for a suggestion that works with typescript.

Any suggestion / direction will be greatly appreciated. Thanks.

Edit:

I tried the suggestion provided by "Get Off My Lawn" but, typescript is not recognizing the createTextRange() and showing error.

JGV
  • 5,037
  • 9
  • 50
  • 94

1 Answers1

1

The .select() event is limited to <input type="text"> fields and <textarea> boxes.

Neil Docherty
  • 555
  • 4
  • 20