JSFiddle - React, Tailwind, and code Playground

HTML

<div id="c">
    Center me!
</div>

CSS

#c {
    background:cyan;
    width:200px; height:200px;
    position:absolute; top:50px; left:50px;
}

JavaScript

$.fn.centerMe = function () {
    this.css('left', $(window).width()/2 - $(this).width()/2);
};

$(window).resize(function() { $('#c').centerMe(); });

$('#c').centerMe();