JSFiddle - React, Tailwind, and code Playground

by Carlos Medina

HTML

<textarea name="area1" cols="40" id="test22"></textarea>
<button onclick="document.getElementById('test22').select();">CLICK</button>

CSS

#test22::selection {
background:#0F0;
color:#fff;
}

JavaScript

function test(){
document.getElementById('test22').setSelectionRange(0, this.value.length)
}