You are binding the event handler inline in HTML also you are using jQuery to bind again inside the function which is not correct.

Just remove the inline onclick,

<input type="button" id="ImageHosting" value="To Image Hosting" />

And change JS

$(document).ready ( function () {
    $("#ImageHosting").click(function () {
       alert("test");
    });
});

Incase if this button is inserted dynamically then,

$(document).ready ( function () {
    //replace document below with enclosing container but below will work too
    $(document).on('click', "#ImageHosting", function () {
       alert("test");
    });
});

Use .live/.delegate if you older version of jQuery ( < 1.7)

Answer from Selvakumar Arumugam on Stack Overflow
🌐
W3Schools
w3schools.com › js › tryit.asp
W3Schools Tryit Editor - JavaScript Alert
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript onclick alert
JavaScript onclick Alert | How does JavaScript onclick Alert work?
October 18, 2022 - Whenever the user click the onclick event it will be handled by the onclick event handler in back end some times in onclick event having alert function on the same web page so it will perform two event operations at the same time.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
University of Washington
washington.edu › accesscomputing › webd2 › student › unit5 › module2 › lesson1.html
Lesson 1: Using JavaScript to Show an Alert
The button includes the onclick attribute, which causes the showAlert() to be called when a user clicks the button. The onclick event also works for keyboard users. If a user navigates to the button using the tab key, then presses enter, that too will trigger the alert.
🌐
TutorialsPoint
tutorialspoint.com › javascript-create-an-alert-on-clicking-an-html-button
JavaScript - Create an alert on clicking an HTML button
March 11, 2025 - var pressedButton = document.getElementsByTagName("button")[0]; pressedButton.addEventListener("click", function (event) { alert("You have pressed the button..........") }) Below is an example of creating an alert by clicking an HTML button in JavaScript ?
🌐
IncludeHelp
includehelp.com › code-snippets › display-alert-message-on-button-click-event.aspx
Display Alert Message on Button Click Event using JavaScript
<!--Display Alert Message on Button Click Event.--> <html> <head> <title>Display Alert Message on Button Click Event.</title> <script type="text/javascript"> function showMessage() { alert("Hello friends, this is message."); } </script> </head> <body> <center> <h1>Display Alert Message on Button Click Event.</h1> <b>Click on button to display message: </b><br /> <br /> <input type="button" id="btnShowMsg" value="Click Me!" onClick="showMessage()" /> </center> </body> </html>
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-use-the-alert-method-in-javascript
How to use the alert() method in JavaScript ? - GeeksforGeeks
July 23, 2025 - <!DOCTYPE html> <html lang="en"> <head> <style> body { /* path of the image */ background-image: url(gfg_complete_logo_2x-min.png); /* Image is always centered*/ background-position: center center; /* set the image fixed to the viewport */ background-attachment: fixed; /* Not repeat image */ background-repeat: no-repeat; /* Set background size auto */ background-size: auto; } </style> </head> <body> <div style="margin-left: 500px; margin-top: 300px;"> <button style="font-size: 20px;" class="btn" onclick="fun()"> click me </button> </div> <script> function fun() { alert("Welcome on gfg!"); } </script> </body> </html>
Find elsewhere
🌐
Indiana
info.sice.indiana.edu › ~hrosenba › Demo › javascript › 6alert.html
Alert and Confirm
In the examples where the code is triggered by a button click, the entire code must by contained in quotation marks: onClick="alert( 'Your Message Here...' )" Without the "onClick" syntax, the outside quotation marks are unnecesssary and will cause an error so they should be left out: alert( 'Your Message Here...' ) JavaScript Triggers JavaScripts can be triggered by user · events such as clicking on a button or loading a web page.
🌐
Codecademy
codecademy.com › forum_questions › 512d28a06918338f2300e9ea
How to make a html button clickable and to show alert on it ? | Codecademy
<script> function clickAlert() { alert("Alert!"); } </script> <input type="button" onclick="clickAlert()" value="Click-2-Alert"> ... May be it will help you…. <head> <script type="text/javascript"> function conf() { var con=confirm("Do you ...
🌐
TutorialsPoint
tutorialspoint.com › javascript-how-to-get-an-alert-to-appear-when-i-click-on-a-button-in-a-class
JavaScript how to get an alert to appear when I click on a button in a class?
October 4, 2024 - On running the above code, a button will appear clicking on which an alert window will pop up. Here, we use the addEventListener() method to associate an event handler, an alert in this case. When we use this method, the JavaScript code would be separated from the HTML markup.
🌐
W3Schools
w3schools.com › js › js_popup.asp
JavaScript Popup Boxes
The window.alert() method can be written without the window prefix. ... A confirm box is often used if you want the user to verify or accept something. When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.
🌐
Sololearn
sololearn.com › en › Discuss › 2801433 › onclick-alert-functions-in-js
Onclick Alert Functions In JS | Sololearn: Learn to code for FREE!
So I finished learning Javascript (I didn't learn it on Sololearn I learned it on a different coding platform) and JQuery a while ago, but I forgot how to use the onclick function that outputs an alert when you click an HTML button.
🌐
W3Schools
w3schools.com › jsref › event_onclick.asp
onclick Event
The onclick event occurs when the user clicks on an HTML element.