Replace Styles Javascript

function onContentLoaded(response)
{
    // Parse the JSON into a Javascript object.
    var data = JSON.parse(response);

    // The content goes into the designated container.
    contentContainer.html(data[0]);
    
    // The styles are replaced.
    addMissingStyles(data[1]);
}

function addMissingStyles(css)
{
    if(css == '')
    {
        return;
    }
    
    // First I remove the old wrong styles.
    var siteOriginId = "#siteorigin-panels-layouts-head";
    tryRemove(siteOriginId);
    
    // Dann I manually embed the new styles.
    var styles = '<style type="text/css" media="all" id="'+siteOriginId+'">'+css+'</style>';
    $('head').append(styles);
}

function tryRemove(id)
{
    var element = document.getElementById(id);
    if(element !== null)
    {
        element.parentNode.removeChild(element);
    }
}