JSFiddle - React, Tailwind, and code Playground

by rwaldron

HTML

<p>
    This is a <span id="span"> SPAN </span> element.
</p>

CSS

span { display:none; }

JavaScript

var elemdisplay = {};

function defaultDisplay( nodeName ) {
    if ( !elemdisplay[ nodeName ] ) {
        var elem = jQuery("<" + nodeName + ">").appendTo("body"),
            display = elem.css("display");

        elem.remove();

        if ( display === "none" || display === "" ) {
            display = "block";
            console.log("display", display, nodeName )
        }

        elemdisplay[ nodeName ] = display;
    }

    return elemdisplay[ nodeName ];
}
jQuery.fn.show = function( speed, easing, callback ) {
    var elem, display;
    
    if ( speed || speed === 0 ) {
        return this.animate( genFx("show", 3), speed, easing, callback);
    
    } else {
        for ( var i = 0, j = this.length; i < j; i++ ) {
            elem = this[i];
            display = elem.style.display;
    
            // Reset the inline display of this element to learn if it is
            // being hidden by cascaded rules or not
            if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
                display = elem.style.display = "";
            }
    
            // Set elements which have been overridden with display: none
            // in a stylesheet to whatever the default browser style is
            // for such an element
            if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
                jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
            }
        }
    
        // Set the display of most of the elements in a second loop
        // to avoid the constant reflow
        for ( i = 0; i < j; i++ ) {
            elem = this[i];
            display = elem.style.display;
    
            if ( display === "" || display === "none" ) {
                elem.style.display = jQuery._data(elem, "olddisplay") || "";
            }
        }
    
        return this;
    }
}
    

$('#span').show();