JSFiddle - React, Tailwind, and code Playground

by Jon-Carlos Rivera

HTML

<form>
    <div>Don't want this one</div>
    <input type="text">
</form>
<form>
    <div>Nor this one</div>
    <input type="text">
</form>
<form>
    <div>That's the one!</div>
    <input type="text">
    <script>
        document.write('<span id="ugly-hack" style="display:none;"></span>');
        
        var form = document.getElementById('ugly-hack');
        while (form.parentNode && form.tagName !== "FORM") form = form.parentNode;

        // form is now our parent form or the root document (if we aren't inside a form at all!)
        
        //proof:
        form.getElementsByTagName("input")[0].style.border = "3px solid red";
    </script>
</form>
<form>
    <div>Don't even bother with this one</div>
    <input type="text">
</form>