JavaScript is an interpreted language, its source programs embedded or integrated into html files. when the page is loaded in a browser that supports javascript, the browser interprets and executes instructions javascipt.
javascript is one of the popular programming language in the world, it is the language of html, web, server, pc, laptop, tablet, smart phone ...
- JavaScript is a scripting language
- scripting language is a programming language small.
- Javascript is a programming code that can be inserted into the html page.
- javascript is inserted into the web page can be run by all modern web browsers.
- JavaScript is a programming language is easy to learn.
1 features of java script language:
JavaScript is a language with features:
- simple.
- action (dynamic).
- object (object oriented).
2 language java script:
one of the important features of the JavaScript language is the ability to create and use objects (object). This object allows the programmer to use to develop applications.
in JavaScript, the object is seen under two aspects:
the object already exists.
objects built by programmers.
3. how to embed javascript into html file
there are 2 ways to embed javascript into html file
way 1: Write a program that directly javascript in html file
<script type = "text / javascript">
// javascript commands
</ script>
ways 2: using external javascript file:
css just like offline, we can also embed javascript into html file by connecting to an external file, this is the method used most.
with this method, the JavaScript command will be written in a separate file extension is .js (eg have my.js file)
demo.js to embed files into html files we use the following code:
<script type = "javascript" src = "demo.js" type = "text / javascript"> </ script>
4 javascript some examples:
javascript: open write in html
<! doctype html>
<html>
<body>
<p>
trực can write javascript into the html output stream:
</ p>
<script>
document.write ('<h1> this is a heading </ h1> ");
document.write ('<p> this is a paragraph. </ p> ");
</ script>
<p>
you can only use <strong> document.write </ strong> in the html output.
if you use it after the document has loaded (eg in a function), the whole document Will Be overwritten.
</ p>
</ body>
</ html>
you can only open using document.write in html (html output). If you use after the document is loaded, the entire content of the document will be overwritten.
javascript: used to capture user events
<! doctype html>
<html>
<body>
<h1> My first javascript </ h1>
<p>
React to events can javascript. like the click of a button:
</ p>
<button type = "button" onclick = "alert ('Welcome!')"> click me </ button>
</ body>
</ html>
function alert () is not used much in javascript. but it is often quite convenient to print out the code.
onclick event is just one of many events your html will be known in the self-study process javascript
javascript: change the html content
use javascript to use the contents of the html element is a very powerful function.
<! doctype html>
<html>
<body>
<h1> My first javascript </ h1>
<p id = "demo">
javascript can change the content of an html element.
</ p>
<script>
function myfunction ()
{
x = document.getElementById ("demo"); // Find the element
x.innerhtml = "javascript hello!"; // Change the content
}
</ script>
<button type = "button" onclick = "myfunction ()"> click me </ button>
</ body>
</ html>
you will often use document.getElementById ("some id"). this is defined in the html.
DOM (Document Object Model) is the official standard provided by the organization to access the w3c html element.
note: JavaScript and Java programming languages are two completely different, even in concept and design. java (built by Sun) is a complex programming language like c of the same type. JavaScript was invented by Brendan Eich. it appears in netscape (a browser defunct) in 1995, and has been adopted by ECMA (an association standards) since 1997