Show Alert Message On Click Using JavaScript.

Show Alert Message On Click Using JavaScript

Here is an example to show the alert message on click using the JavaScript.

Show Alert Message on Click of a Link Using JavaScript

In the below example, when the user will click on the link, it will show the alert message using the JavaScript.

The Script for the HTML HEAD Part:

<style>
    *.alert-image {
        cursor:pointer;
        margin-left:3px;
    }
    *.alert       {
        cursor:pointer;
        border-bottom:1px dotted;
        font-style:normal;
        font-size:0.8em;
    }
    body {
        margin:0px;
        padding:20px;
        padding-top:0px;
        width:702px;
        font-family:verdana,arial,sans-serif;
        font-size:18px;
    }
    h1   {
        margin:0;
        margin-top:10px;
        font-size:30px;
    }
    p    {
        margin:0;
        margin-top: 20px;
    }
</style>

The Script for the HTML BODY Part:

<h1>
    Show JavaScript Alert on Click
</h1>
<p>
    A JavaScript alert will be dispalyed when the user click on the following icon and link. 
    Click on the following image
    <img class="alert-image" 
    onclick="alert('Here is the Alert message.');" src="help.gif" alt="alert" />
    or click on the following text
    <em class="alert" onclick="alert('Show Alert');" >
        dotted underline.</em>
</p>

Output

As shown in the featured image of this article.