Spedwards
Spedwards

Reputation: 4492

Textarea highlight on focus

I'm trying to have all the contents in a textarea highlight when it gains focus. Currently, as soon as it gains focus the contents will be highlighted but it immediately loses it.

This is what I'm using:

<textarea onfocus="this.select()" readonly>Test</textarea>

Fiddle: http://jsfiddle.net/spedwards/Mr2ja/

Upvotes: 2

Views: 557

Answers (1)

adeneo
adeneo

Reputation: 318162

You have prevent the mouseup event as well, as it fires after the focus is set and deselects the contents

<textarea onfocus="this.select()" onmouseup="return false;" readonly="readonly">Test</textarea>

FIDDLE

Upvotes: 3

Related Questions