<script>
function classEdit(){
d1 = document.getElementsByClassName('d1')[0];
if(d1){
d1.className = 'd2';
setTimeout(classEdit, 2000);
}
}
</script>
<div id="r1" class="d1" onclick="classEdit()">d1</div>
<div id="r2" class="d1">d2</div>
<div id="r3" class="d1">d3</div>
<div id="r4" class="d1">d4</div>