JSFiddle - React, Tailwind, and code Playground

by Aaron Zhang

HTML

<div style="width:100px;height:100px;"></div>
<div id="inverse" style="width:100px;height:100px;"></div>

CSS

div{
    background-color:rgb(40,123,123);
}

JavaScript

function inverse(num) {
    if (num < 127) {
        return 128 + (127 - num);
    } else {
        return 128 - (num - 127);
    }
}
$(document).ready(function () {
    var arr = $('div#inverse').css('background-color').replace('rgb(', '').replace(')', '').replace(/ /g, '').split(',');
    var R = arr[0];
    var G = arr[1];
    var B = arr[2];
    $('div#inverse').css('background-color', 'rgb(' + inverse(R) + ',' + inverse(G) + ',' + inverse(B) + ')');
});