Attach function to dynamically created DOM element
<p><strong>Goal:</strong></p>

<p>Append a DOM element with functionality. (One global listener is not desire here.)</p>

<p><strong>Problem:</strong></p>

<p>I don't know how to reference the new element in this context. The problem area is the <code>.on</code> event listener and the references to <code>$(this)</code> contained inside. Also, the ability for the function <code>get_value()</code> to call itself again from within.</p>

<p><strong>Relevant Code:</strong></p>

<pre><code>var dom_element = (function() {
    // [...]
    var create = function create( data ) {
        // [...]
        return $('&lt;div /&gt;', { 'class': 'element', id: data.i_id })
            // [...]
            .on('load', function get_value() {
                // [...]
                $(this).find('.value').text(s_value);
                // [...]
                setTimeout('get_value()', 5000);
            }());
    },
    // [...]
    return {
        create: create
    };
}());
</code></pre>
