vladik3333,
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<span class="task">текст1</span>
<span class="task">текст2</span>
<span class="task">текст1</span>
<span class="task">текст3</span>
<span class="task">текст2</span>
<script>
function test1(){
var twe = document.querySelectorAll("span[class='task']");
var ob = twe.length;
if(ob == 5) for(var {textContent} of twe) alert(textContent);
}
test1()
</script>
</body>
</html>