Pass Javascript element as variable
<p>I'm doing some testing for an AngularJS app, I don't think the test framework is necessarily important here, but I'm trying to pass an optional variable. This variable will specify if I'm trying to grab a child element of the ID that is passed to the function</p>

<pre><code>commonFunctions.elementDoesNotHaveAttribute('register-0', 'disabled', 'children[0].children[0]');
</code></pre>

<p>the <code>children[0].children[0]</code> isn't really a string, if I remove the quotes the function call fails because it can't find a child object of <code>.children[0]</code></p>

<p>Here is the function</p>

<pre><code>function elementDoesNotHaveAttribute(id, attribute, child) {
    var hasElement = false;

    hasElement = casper.evaluate(function (id, attribute, child) {
        var element = document.getElementById(id);
        if (child) {
            element = element.child;
        }        
        return element.hasAttribute(attribute);
    }, id, attribute, child);

    if (hasElement) {
        casper.test.fail('element has' + attribute + ' but shouldn\'t');
    } else {
        casper.test.pass('element didn\'t have ' + attribute + ' and shouldn\'t');
    }
}
</code></pre>

<p>How can I change either side of these equations to end up evaluating <code>element.children[0].children[0]</code> within my function</p>