A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/html-css-exercise/basic/script-answer.php below:

Website Navigation


HTML5: How to define a client-side script?

HTML5: How to define a client-side script?Last update on February 12 2024 12:52:01 (UTC/GMT +8 hours)

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html><!-- Define document type as HTML5 -->
<html><!-- Start of HTML document -->
<head><!-- Start of head section -->
<meta charset="utf-8"><!-- Define character encoding -->
<title>How to define a client-side script</title><!-- Title of the document -->
</head><!-- End of head section -->
<body><!-- Start of body section -->
<p id="output">Click Me</p><!-- Define a paragraph with an id for interaction -->
<script type="text/javascript"><!-- Start of JavaScript script -->
function w3r(){  // Define a JavaScript function named "w3r"
console.log('This is an example of script element');  // Output a message to the browser console
}   
var el = document.getElementById('output'); // Get the element with the id "output"
el.addEventListener("click", w3r, false); // Add a click event listener to the element, calling the "w3r" function
</script><!-- End of JavaScript script -->
</body><!-- End of body section -->
</html><!-- End of HTML document -->

Explanation:

Live Demo:

See the Pen script-answer by w3resource (@w3resource) on CodePen.

See the solution in the browser

Supported browser

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4