ash ash - 29 days ago 9
HTML Question

Javascript function button

I have created a button in HTML:

<div class="button">
<p id="demo"></p>
<button onclick="button1()">Grayscale</button>
</div>


However, I need the button to link to the javascript function below:

function clickInfoGreyscale() {
/* Code */
}


How is the button linked to the javascript function?

Answer

Just change the click event to fire clickInfoGreyscale() instead of button1.

function clickInfoGreyscale() {
   /* Code */
  alert('I am grey');
}
<div class="button">
    <p id="demo"></p>           
    <button onclick="clickInfoGreyscale()">Grayscale</button>
</div>