<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div id="preview_main_block">
<div class="preview" id="slider_slide1">1</div>
<div class="preview" id="slider_slide2">2</div>
<div class="preview" id="slider_slide3">3</div>
</div>
<script>
var elems = document.querySelectorAll(".preview");
Array.prototype.forEach.call(elems, function(val, i)
{
val.onclick = function ()
{
alert(i+1);
}
}
);
</script>
</body>
</html>