How to display the value of first_name in a div block?

function getInfo() { FB.api('/me', 'GET', {fields: 'first_name,last_name,name,id,email'}, function(response) { document.getElementById('status').innerHTML = response.first_name; }); } 

Output in <div id="status"></div> , but after clicking on Get Info, how to do it without clicking, but right away?

  • what's wrong with the above code? - Grundy
  • Yes, the question was not so, I added it. - bakusite

3 answers 3

 $( document ).ready(function() { getInfo(); }); 

     // При загрузки скрипта document.getElementById("result").innerHTML = "Hello!!"; // После того как страница загруженна function resultOnLoad() { document.getElementById("result").innerHTML = "Результат функции resultOnLoad!"; } // По клику на кнопку function resultToDiv() { document.getElementById("result").innerHTML = "Привет, мир!"; } 
     <body onload="resultOnLoad()"> <div id="result"></div> <input type="button" onclick="resultToDiv()" value="Click me!"> </body> 

    • something is not displayed value in the result div, strange - bakusite
     window.addEventListener("load", function (){ getInfo() },false);