Search code examples
javascripthtmlfunctionbuttononload

Button onload calls function


I have the following button

<button type="button"
  title="Previous value:"
  ***onload="test()"***
  class="btn btn-warning mb-2" style="padding: 4px 8px 4px 8px; border-radius: 1rem;">
 <i class="fas fa-exclamation-triangle text-white"></i>
</button>

Which I want it when it loads to call the test() function

function test() {
    console.log("I am in");
}

in reality this function will be creating a popover. But it doesnt seem to be calling the function. (No, onclick or hover is not helping me.)

Any suggestions, ideas how to achieve that?

Many thanks in advance.


Solution

  • onload event is only supported on these HTML tags:

    <body> <iframe> <img> <input type="image"> <link> <script> <style>
    

    take a look at: HTML onload attribute