Replace WP logo with H1 using JS

Solution:1

You can use replaceWith

$("h1").replaceWith('<a href="http://example.com/"><h1 class="entry-title">replaceWith</h1></a>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>Test</h1>

Solution:2

<div class="site-branding">             
    <?php
    $logo_id = get_theme_mod( 'custom_logo' );
    $logo_image = wp_get_attachment_image_src( $logo_id, 'full' );                  

    if ( ! empty( $logo_image ) ) : ?>
        <span class="site-logo"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><img src="<?php echo esc_url( $logo_image[0] ); ?>" alt="<?php bloginfo( 'name' ); ?>"/></a></span>
    <?php else : ?>
        <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
    <?php
    endif;      
</div><!-- .site-branding -->