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.

2
  • 2
    @Anthony that probably won't work as the OP probably wants to highlight it so the user can do ctrl+c to copy it to the clipboard. Commented Nov 22, 2016 at 22:25
  • I have updated the question and title Commented Nov 23, 2016 at 21:27

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.