elems= document.getElementsByClassName(clasS); var i=0; while(i!== elems.length && elems[i].tagName !== "div") ++i; if (i === elems.length) alert("Не найдено") else div_with_class=elems[i];