JSFiddle - React, Tailwind, and code Playground

by landongw

HTML

<div id="yes">
yes
</div>
<div id="no">
no
</div>
<div id="save">
save
</div>

JavaScript

// max the form window
        function clickMaxBtn() {
            $('div.max-btn').click();
            console.log('max button clicked yo');
        }

        // checks if a svg drawing is present
        function checkDrawingComplete() {
            let svg = $("[id*='lfl_layer']");
            console.log(svg.length);
            if (svg.length === 0) {
                setTimeout('checkDrawingComplete()', 300);
            } else {
                clickMaxBtn();
                checkFormComplete();
                console.log('clicky');
            }
        }

        function checkFormComplete() {

            let yes = $("div:contains('Yes')").on("click", function() {
                clickMaxBtn();
                checkDrawingComplete();
                console.log('restart checkDrawingComplete');
            });

            let no = $("div:contains('No')").on("click", function() {
                clickMaxBtn();
                checkDrawingComplete();
                console.log('restart checkDrawingComplete');
            });

            let save = $("div:contains('Save')").on("click", function() {
                clickMaxBtn();
                checkDrawingComplete();
                console.log('restart checkDrawingComplete');
            });

            if (yes.length === 0 && no.length === 0 && save.length === 0) {
                setTimeout('checkFormComplete()', 600);
            }
        }
        
        

        // TODO listen for click on pain or numbness button before checkDrawingComplete
        checkDrawingComplete();