How to create a function which can work on future elements?
<p>Assume that i have a function that add a border to the element:</p>

<pre><code>$.fn.border = function() {
    $(this).css('border', '1px solid red');
}
</code></pre>

<p>and i add to to my document ready:</p>

<pre><code>$(document).ready(function() {
    $('.elem').border();
});
</code></pre>

<p>This will work fine, but now if i need to add other elements to the dom via ajax, they won't get the border. Are there any way to delegate this to future elements?</p>

<p>something similar to this click event:</p>

<pre><code>$('div').on('click', 'a', function() {
    // do something
})
</code></pre>