Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
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>
Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.
Start Free TestingEarn resume-worthy Selenium certifications that help you land a top job.
Learn MoreTest orchestration and execution cloud of 3000+ browsers and OS
24/7 support
Enterprise grade security
Fastest test execution cloud