<div class="button"><div>
<div class="class-main">
<div class="class">1</div>
<div class="class">2</div>
<div class="class">3</div>
</div>
const className = 'class';
const index = 1;
const element = document.querySelector(`.${className}:nth-child(${index + 1})`);
const element = document.querySelectorAll('.' + className)[index];
// или
const element = document.getElementsByClassName(className).item(index);
<div class="button">Button</div>
<div class="class-main">
<div class="class">1</div>
<div class="class">2</div>
<div class="class">3</div>
</div>
<script type="text/javascript">
document.getElementsByClassName("button")[0].onclick=function(){
console.log(document.getElementsByClassName("class")[1])
}
</script>