Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
JavaScript or JS is a client-side scripting language to build modern and interactive web applications. As JavaScript is not standalone, you must rely on HTML to run your software programs.
There are three ways to include JavaScript in your HTML pages.
Embedding code: To include JavaScript code in your HTML pages, use the <script>.....</script> HTML tag containing JavaScript code. You can add the JavaScript code in the <body> or <head> tag.
Example:
<!DOCTYPE html >
<html>
<head>
<title>LambdaTest</title>
<script>
document.write("A Test Orchestration & Execution Platform");
</script>
</head>
<body>
<p>Welcome to LambdaTest!</p>
</body>
</html>
Inline code: This method calls a function in the HTML event attributes without using the <script>.... </script> tag.
Example:
<!DOCTYPE html >
<html>
<head>
<title>LambdaTest</title>
</head>
<body>
<p>
<a href="#" onClick="alert('Want to test?');">Register here</a>
</p>
<p> Welcome to LambdaTest </p>
</body>
</html>
External file: It involves creating a JavaScript file to hold the code of JavaScript explicitly. After that, add that JavaScript file to your HTML document using the src attribute of the HTML <script> tag.
Example:
<html>
<head>
<meta charset="utf-8">
<title>LambdaTest</title>
</head>
<body>
<form>
<input type="button" value="Register" onclick="display()"/>
</form>
<script src="index.js">
</script>
</body>
</html>
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.