Chapter Four - Javascript (JS)
Chapter Four - Javascript (JS)
JavaScript (JS)
Outline
Introduction to Events
Javascript ✓ HTML Event Handler
✓ Dom Event handler
✓ Variables (as a method)
✓ Functions ✓ Event Listener
✓ Objects
DOM
✓ Accessing elements
✓ Changing content
✓ Changing attributes
Introduction to Java script
Dynamic HTML (DHTML) is a grouping of technologies used
to create interactive web pages, which are also referred to
as dynamic web pages.
Interaction implies that you can do something to a page and
have it respond to your actions.
For example, you can click button to change the
appearance of an image on the page.
DHTML is not a special version of HTML. Or even a version
of HTML at all. Instead DHTML consists of a combination of
the following three web technologies.
✓ HTML
✓ Cascading Style Sheet (CSS)
✓ Web Scripting (like JavaScript, PHP scripting)
With the combination of the above three, the web page is no
longer static when you create the page.
Using Web script, you can alter the style of the web content
based upon user interaction such as clicking and dragging the
mouse.
In web there are two types of scripting: Client and Server-side
scripting.
Client-side script is executed on the web browser (client
machine). Script written with JavaScript or jQuery library runs
on the web browser machine.
Server-side script executed on the web server, Script written
with PHP, JAVA, C# runs on the web browser machine.
Adding Javascript to a page
Embedded Script: to embed a script on a page, just add the
code as the content of a script.
External Script: The other method uses the src attribute to point
to a script file (with a .js suffix) by its URL. In this case, the script
element has no content:
Comparison Operators
Operator Description Example
== is equal to 5==8 returns false
=== is equal to (checks for both value x=5
and type) y="5"
Conditional statements
✓ if, if else
✓ switch
looping
✓ while
✓ do … while
✓ for
conditional operator
✓ var_name = (condition) ? true_value : false_value
✓
Function
Function can be defined into two ways: named function or
function expression.