Skip to main content

in JavaScript code:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
  call_your_function_here();
});
</script>

Here we created an event listener it means when the document is fully loaded the function() will be called, using the same way you can add any event listener to any DOM object, ex. you have a button with id="test", var btest = document.getElementById('test'); then

btest.addEventListener('click', function() { //execute code if btest object was clicked });

Bottom line you should call your function when the document is fully loaded hence replace the call_your_function_here() with your function name and if you wanted to reference the same button your function was embedded in use this syntax to reference the button DOM object:

var buttonObj = document.getElementById(buttonID);

then supply buttonObj to your function's argument.

in JavaScript code:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
  call_your_function_here();
});
</script>

Here we created an event listener it means when the document is fully loaded the function() will be called, using the same way you can add any event listener to any DOM object, ex. you have a button with id="test", var btest = document.getElementById('test'); then

btest.addEventListener('click', function() { //execute code if btest object was clicked });

Bottom line you should call your function when the document is fully loaded hence replace the call_your_function_here() with your function name and if you wanted to reference the same button your function was embedded in use this syntax to reference the button DOM object:

var buttonObj = document.getElementById(buttonID);

then supply buttonObj to your function's argument.

in JavaScript code:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", call_your_function_here);
</script>

Here we created an event listener it means when the document is fully loaded the function() will be called, using the same way you can add any event listener to any DOM object, ex. you have a button with id="test", var btest = document.getElementById('test'); then

btest.addEventListener('click', function() { //execute code if btest object was clicked });

Bottom line you should call your function when the document is fully loaded hence replace the call_your_function_here() with your function name and if you wanted to reference the same button your function was embedded in use this syntax to reference the button DOM object:

var buttonObj = document.getElementById(buttonID);

then supply buttonObj to your function's argument.

Formatting
Source Link
Charles Menguy
  • 41.6k
  • 18
  • 97
  • 117

in JavaScript code:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
  call_your_function_here();
});
</script>

Here we created an event listener it means when the document is fully loaded the function() will be called, using the same way you can add any event listener to any DOM object, ex. you have a button with id="test", var btest = document.getElementById('test'); then btest.addEventListener('click', function() { //execute code if btest object was clickedid="test", });var btest = document.getElementById('test'); then

btest.addEventListener('click', function() { //execute code if btest object was clicked });

Bottom line you should call your function when the document is fully loaded hence replace the call_your_function_here()call_your_function_here() with your function name and if you wanted to reference the same button your function was embedded in use this syntax to reference the button DOM object:

var buttonObj = document.getElementById(buttonID);

then supply buttonObj to your function's argument.

in JavaScript code:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
  call_your_function_here();
});
</script>

Here we created an event listener it means when the document is fully loaded the function() will be called, using the same way you can add any event listener to any DOM object, ex. you have a button with id="test", var btest = document.getElementById('test'); then btest.addEventListener('click', function() { //execute code if btest object was clicked });

Bottom line you should call your function when the document is fully loaded hence replace the call_your_function_here() with your function name and if you wanted to reference the same button your function was embedded in use this syntax to reference the button DOM object:

var buttonObj = document.getElementById(buttonID);

then supply buttonObj to your function's argument.

in JavaScript code:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
  call_your_function_here();
});
</script>

Here we created an event listener it means when the document is fully loaded the function() will be called, using the same way you can add any event listener to any DOM object, ex. you have a button with id="test", var btest = document.getElementById('test'); then

btest.addEventListener('click', function() { //execute code if btest object was clicked });

Bottom line you should call your function when the document is fully loaded hence replace the call_your_function_here() with your function name and if you wanted to reference the same button your function was embedded in use this syntax to reference the button DOM object:

var buttonObj = document.getElementById(buttonID);

then supply buttonObj to your function's argument.

Source Link
Ahmed Jolani
  • 3.2k
  • 2
  • 22
  • 24

in JavaScript code:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
  call_your_function_here();
});
</script>

Here we created an event listener it means when the document is fully loaded the function() will be called, using the same way you can add any event listener to any DOM object, ex. you have a button with id="test", var btest = document.getElementById('test'); then btest.addEventListener('click', function() { //execute code if btest object was clicked });

Bottom line you should call your function when the document is fully loaded hence replace the call_your_function_here() with your function name and if you wanted to reference the same button your function was embedded in use this syntax to reference the button DOM object:

var buttonObj = document.getElementById(buttonID);

then supply buttonObj to your function's argument.