Open mrm7moud opened 7 years ago
Use Self-Invoking Function directly in dom function example:
(function dom() { if (typeof document != 'undefined') { var searchForm = document.getElementById('searchForm'); if (searchForm) { searchForm.addEventListener('submit', function(event){ event.preventDefault(); var userName = event.target.firstElementChild.value; apiReq(userName , function(data){ document.querySelector('.avatar img').setAttribute("src", data.avatar_url); document.querySelector('.names h1').textContent = data.name; document.querySelector('.names h6').textContent = data.login; document.querySelector('#company').textContent = data.company; document.querySelector('#location').textContent = data.location; document.querySelector('#followersNumber span').textContent = data.followers; document.querySelector('#followingNumber span').textContent = data.following; document.querySelector('.listRepos').innerHTML = myRepos(data.repos); }); }); } } })();
https://github.com/FACG2/getGitHub/blob/2b645470496b5717e3ee73381e64079f0e1adc68/public/js/index.js#L1
its the samethink mahmoud, we are using the self-invoking function. but we call the dom inside it because we were thinking of invoking other functions in the same self-invoking function. Thank you mahmoud ^^
Use Self-Invoking Function directly in dom function example:
https://github.com/FACG2/getGitHub/blob/2b645470496b5717e3ee73381e64079f0e1adc68/public/js/index.js#L1