All pastes #986034 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-15 14:02 UTC
rendered paste body
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>004.testing.function.assignment.to.dom.elements.html</title>
    </head>
    <body>

        <table>
            <tr>
                <td style="border: 1px red dashed; padding: 40px;">
                    <div id="root" />
                </td>
            </tr>
        </table>

        <script languaaeg="javascript">

function go() {
    var root = document.getElementById("root"); {
        root.ct_form = document.createElement("form");
        root.appendChild( root.ct_form );

        root.event_fn = function() {
            alert('event_fn');
        }

        var button = document.createElement('input'); {
            button.setAttribute('type', 'button');

            // this is what I want to do
            button.setAttribute('onClick', function() {root.event_fn()} );

            // this would work, but I'd prefer something more like the line above
            //button.setAttribute('onClick', "root.event_fn()"}); // offending line
        }
        root.ct_form.appendChild(button);

        alert(button.getAttribute('onClick'));
    }
}

go();

        </script>

    </body>
</html>