<div class="month" data-month="3">
<div class="week">
<div class="day">
3
</div>
</div>
</div>
<div class="month" data-month="4">
<div class="week">
<div class="day">
13
</div>
</div>
</div>
<script>
[].forEach.call(document.querySelectorAll('.day'), function(el){
while (el = el.parentNode) {
if (el.dataset.month) {
console.log(el.dataset.month);
break;
}
}
});
</script>
более универсальное решение