HTML Onclick EventsThe HTML on-click events work on HTML elements and input tags. We can click on the input tag, button, and other HTML elements to operate the function. The function's script can be in either HTML or JavaScript code. If the script of the on-click events is complicated, use JavaScript; otherwise, use it in the HTML tag. SyntaxThe following syntax is used for HTML onclick events in HTML elements or tags. Description
ExamplesThe following examples show the html onclick function with the simple script operation. Example 1 The following examples operate on click event in html tag with the basic code. We can use the button for the script operation. Output: The output shows the on-click event on the button and its operation. Example 2 The following examples operate an onclick event in html tag with the script code. We can use the input tag with the submit type for the script operation. Output: The output shows the onclick event on the input submit type and its operation. Example 3 The following examples operate an onclick event in html input tag with the script code. We can use the input tag with text type for the script operation. Output: The output shows the onclick event on the input text type and its operation. Example 4 The following examples operate an onclick event in html input tag with the script code. We can use the input tag with text type for the script operation. Output: The output shows the onclick event on input tags and its operation. Example 5 The following examples operate on the click event in the HTML tag with the JavaScript function. We can use the input tag with submit and button type for the script operation. We can use JavaScript code for the onclick event. Output: The output shows the onclick event on input tags with JavaScript code. ConclusionThe onclick function in HTML is useful for users and developers to validate and notify guidelines of the form. We can change the styles, operation, and javascript function using the onclick event attribute in the html. Next TopicHTML Photo |