how to declare js event and function to every dom element with given tag and class even when these elements don't exist at the moment?
<p>I need to 'decorate' every div.myclass with a function in a way that css is doing it with style, that is some of these elements aren't on a page when this function fires, so I can't just find and loop trough them. Some of the elements are created from ajax requests, and some are changing classes.</p>

<p>In css when an element changes class it's style changes instantly. I also need a similar situation here when for example all divs with class1 would have declared one function and with class2 another, and when I do for example:</p>

<pre><code>document.getElementsByClassName("class1")[0].setAttribute("class", "class2");
</code></pre>

<p>Behavior of that element should change instantly.</p>

<p>I prefer pure js, but if it's there a cleaner jquery or prototype way I also be glad.</p>
