<script type="text/javascript">
var fontSizes = [
"xx-small",
"x-small",
"small",
"medium",
"large",
"x-large",
"xx-large"
];
function getFontSize(id) {
return document.getElementById(id).style.fontSize || "medium";
}
function changeFontSize(id, size = "medium") {
document.getElementById(id).style.fontSize = size;
}
function cycleSize(id) {
let i = fontSizes.indexOf(getFontSize(id)) + 1;
changeFontSize(id, fontSizes[i >= fontSizes.length ? 0 : i]);
}
</script>
<p id="p">Click the button below to change my size!</p>
<button onclick="cycleSize('p')">Change size</button>