Professional Documents
Culture Documents
A Review
JavaScript
JavaScript is a Scripting Language
A scripting language is a lightweight
programming language. JavaScript is
(relatively) easy to learn.
JavaScript code can be inserted into
any HTML page, and it can be
executed by all types of web browsers.
JavaScript
A script is usually written as part of an
HTML document and it controls the
elements of a page and reacts to user
actions.
Error: Can not process
Love me request.
Love me
JavaScript Java
(CMSC 2 and CMSC 100) (CMSC 22)
JavaScript
JavaScript has very little
to do with the
programming language
named Java.
script
JavaScript
<script>
put your javascript
code here
</script>
<script type="text/javascript">
put your javascript
code here
</script>
JavaScript
<body>
<head>
<script>
put your javascript
code here
</script>
</head>
</body>
<script src="myScript.js"></script>
JavaScript
Manipulating HTML Elements
To access an HTML element from
JavaScript, you can use the
document.getElementById(id)
method.
Use the "id" attribute to identify the
HTML element
JavaScript
<body>
<p id="demo">My First Paragraph.</p>
<script>
document.getElementById("demo").
innerHTML="My First JavaScript";
</script>
</body>
JavaScript
<body>
<script>
document.getElementById("demo").
innerHTML="My First JavaScript";
</script>
<p id="demo">My First Paragraph.</p>
</body>
JavaScript
JavaScript Statements
JavaScript statements are
"commands" to tell the browser what
to do.
It is good practice to put a semicolon
at the end of your javascript
statements.
document.getElementById("demo").innerHTML="My First JavaScript";
JavaScript
JavaScript is Case Sensitive
getElementById is not the
same as getElementbyID.