JSFiddle - React, Tailwind, and code Playground
HTML
<span>Select font:</span>
<select onchange=fontSelected(event)>
<option value="default">Browser Default</option>
<option value="Lily+Script+One">Lily Script One</option>
<option value="Freckle+Face">Freckle Face</option>
<option value="Fascinate+Inline">Fascinate Inline</option>
<option value="Londrina+Shadow">Londrina Shadow</option>
</select>
<h1 id="theText">This is a sample text...</h1>
JavaScript
function fontSelected(e){
var select = e.target;
if (select.selectedIndex > 0) { // web font
var fontID = select.options[select.selectedIndex].value;
if (!document.getElementById(fontID)) {
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = fontID;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'https://fonts.googleapis.com/css?family='+fontID;
link.media = 'all';
head.appendChild(link);
}
document.getElementById("theText").style.fontFamily = select.options[select.selectedIndex].innerHTML;
}else{ // default browser font
document.getElementById("theText").style.fontFamily = null;
}
}