<!DOCTYPE html>
<html>
<body>

<p>Click the button to change the color of the image to black and white (100% gray).</p>

<button onclick="myFunction()">Try it</button><br><br>

<img id="myImg" src="pineapple.jpg" alt="Pineapple" width="300" height="300">

<p><strong>Note:</strong> This example does not work in Internet Explorer, Edge 12, or Safari 5.1 and earlier.</p>

<script>
function myFunction() {
    // Standard syntax
    document.getElementById("myImg").style.filter = "grayscale(100%)";

    // Chrome, Safari, and Opera
    document.getElementById("myImg").style.WebkitFilter = "grayscale(100%)";  
}
</script>

</body>
</html>