document.addEventListener('DOMContentLoaded', function() { $(document).ready(function(){ var catalogelem = document.getElementsByClassName('autotwocatalogtitle'); var catalogahref = document.getElementsByClassName('autotwocataloglink'); //alert('bлоков ' + catalogelem.length); //alert('link ' + catalogahref.length); var resultcatalog = catalogelem.length - catalogahref.length; if(resultcatalog>=0){ for (var i = catalogahref.length - 1; i >= 0; i--) { catalogelem[i].setAttribute('id', "block"+i); catalogahref[i].setAttribute('href', "#block"+i); } } else alert('Разделов в каталоге больше, чем блоков Ñ Ñ‚Ð¾Ð²Ð°Ñ€Ð°Ð¼Ð¸. ВернитеÑÑŒ в конÑтруктор.'); }); });