This question has already been answered:
Why, if the data is in the userData array, load through the contact, and then create a list of ul, from this data, and if you try to iterate over the elements with the .igrost class
that are in the muz block, will it not find anything?
http://plnkr.co/edit/5hH9iEYjQ29oB6XUDYlo?p=preview
I tried to lighten the code, made it without contact, and now it finds the elements, but with the contact it does not, why?
https://jsfiddle.net/049x0eeL/
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css"> <script src="http://vk.com/js/api/openapi.js"></script> </head> <body> <div class="container"> <h1 id="headerInfo"></h1> <span class="igrost">play</span> <ul class='muz' id='muz'> </ul> <div class="progress"> <div class="progress-bar progress-bar-danger" data-role="progressbar" style="width: 0%"></div> </div> </div> <script src="script.js"></script> </body> </html> function foo() { VK.init({ apiId: 5580872 }); VK.Auth.login(function(response){ if(response.session){ VK.api('audio.get', {}, response => { if(response.error){ alert(response.error.error_msg); } else{ let userData = response.response; for(var i = 0; i < userData.length; i++){ var ul = document.querySelector('.muz'); var li = document.createElement('li'); li.innerHTML = '<span class="igrost">'+'play '+'</span>' + userData[i].artist + ' - ' + userData[i].title ul.appendChild(li) } } }); } else{ alert('Не удалось авторизироваться') } }, 8); } foo() var igrost = muz.querySelectorAll('.igrost') console.log(igrost) ///////////////////////////////////////
<ul class='muz' id='muz'> </ul> let userData = ['sdfs', 'ggggggg', 'uuuu']; for(var i = 0; i < userData.length; i++){ var ul = document.querySelector('.muz'); var li = document.createElement('li'); li.innerHTML = '<span class="igrost">' +' play ' +'</span>' + '<span>' +userData[i] +'</span>' ul.appendChild(li) } var igrost = muz.querySelectorAll('.igrost') console.log(igrost) for(var m = 0; m < igrost.length; m++){ igrost[m].addEventListener('click', function(e) { console.log(e.target) }) }