can I load a function js in bodybody?

1

I need to know how to call functions js because I do not know how it is done but that it is different from onchange or onclick. The only documentation I have found has been for no answer to my question.

    
asked by Kevin Castaño 18.04.2017 в 03:00
source

3 answers

1

If possible, using the event onload , it will be executed when the page is finished loading, example:

function My_onLoad() {
 alert("Hola mundo!!");
}
<body onload="My_onLoad()">
</body>

I remain attentive to your comments or concerns, Greetings! ;))

    
answered by 18.04.2017 / 03:11
source
1

To load the function at the time of loading the page you just have to use the onload method of javascrpt I leave the example:

function holamundo(){
 console.log("Hola Mundo");
}
<body onload="holamundo()">
</body>
    
answered by 18.04.2017 в 03:18
1

Alternatively to the given answers, you can use a <script> tag before closing the </body> .

<body>
   Aquí va tu contenido html y luego de eso un elemento script. 

   <script>
     // este es un bloque de código que se ejecuta después de que se 
     // cargo todo el documento. 

     alert('hola mundo');

   </script>
   <!-- la idea es no agregar mas elementos aquí -->    
</body>
    
answered by 18.04.2017 в 04:42