JSFiddle - React, Tailwind, and code Playground

HTML

<div id="sbdiv" onclick='alert("submitted")'>submit</div>

JavaScript

jQuery(document).ready(function() {
    var originalEvent = $('div#sbdiv').attr("onclick");
    $('div#sbdiv').attr("onclick", false);
    
    $('div').click(function(e) {
        if (false) {
            // do nothing and let the JS in the onlick attribute do its thing
            
            eval(originalEvent);
        }
        else {
            alert("error");
            // somehow stop the onclick attribute JS from firing
        }

    });
});