JSFiddle - React, Tailwind, and code Playground
HTML
<textarea>Lorem Ipsum dolor sit atem</textarea>
<input type="text" value="Lorem Ipsum dolor sit atem" />
<p>Lorem Ipsum dolor sit atem</p>
CSS
::-moz-selection {
background: black;
color: white;
}
::-webkit-selection {
background: black;
color: white;
}
.selected {
background: black;
color: white;
}
JavaScript
$(document).ready(function(){
$('textarea').focus(function() {
$(this).addClass('selected');
});
$('input').focus(function() {
$(this).addClass('selected');
});
$('textarea').blur(function() {
$(this).removeClass('selected');
});
$('input').blur(function() {
$(this).removeClass('selected');
});
});