kmutnb - internet programming 4/7
DESCRIPTION
Lecture for King Mongkut's University of Technology North Bangkok (KMUTNB) / Computer Science / Internet Programming Course by PHUPHATRANSCRIPT
Cascade Style Sheet & Java Script & DOM
By: Mr. PHUPHA PUNYAPOTASAKUL
(ภู�ผา ปั�ญญาโพธาสกุ�ล)
04/11/23 Free template from www.brainybetty.com 2
Cascading Style Sheets
• CSS stands for Cascading Style Sheets • Styles define how to display HTML elemen
ts • Styles were added to HTML 4.0 to solve a
problem • External Style Sheets can save a lot of work • Multiple style definitions will cascade into
one
04/11/23 Free template from www.brainybetty.com 3
Cascading Order
• Browser default
• External style sheet
• Internal style sheet (inside the <head> tag)
• Inline style (inside an HTML element)
04/11/23 Free template from www.brainybetty.com 4
CSS Syntax
• Syntaxselector {property: value}
• E.g.body {color: black}
• If value have space or special characterp {font-family: "sans serif"}
04/11/23 Free template from www.brainybetty.com 5
CSS Syntax
• Multiple properties (use semi-colon)p
{
text-align: center;
color: black;
font-family: arial
}
• Groupingh1,h2,h3,h4,h5,h6
{
color: green
}
04/11/23 Free template from www.brainybetty.com 6
CSS Syntax
• Class selectorp.right {text-align: right}
p.center {text-align: center}
…
<p class="right"> ..</p>
• Applying more than one class<p class="center bold"> .. </p>
• Class for any tag.right {text-align: right}
04/11/23 Free template from www.brainybetty.com 7
CSS Syntax
• ID Selector#green {color: green}
• ID Selector for specific tagp#green {color: green}
• Applying style<p id=“green”> .. </p>
• Tag with specific attribute
input[type="text"] {background-color: blue}
04/11/23 Free template from www.brainybetty.com 8
CSS Comment
• Start with /* and end with */• Similar to C or JAVA• E.g.
/* This is a comment */p{text-align: center;/* This is another comment */color: black;font-family: arial}
04/11/23 Free template from www.brainybetty.com 9
CSS Pseudo-classes
• Syntaxselector:pseudo-class {property: value}
selector.class:pseudo-class {property: value}
• E.g.a:link {color: #FF0000} /* unvisited link */
a:visited {color: #00FF00} /* visited link */
a:hover {color: #FF00FF} /* mouse over link */
a:active {color: #0000FF} /* selected link */
a.red:visited {color: #FF0000}
04/11/23 Free template from www.brainybetty.com 10
Dreamweaver
04/11/23 Free template from www.brainybetty.com 11
CCS Windows
04/11/23 Free template from www.brainybetty.com 12
Box model
04/11/23 Free template from www.brainybetty.com 13
Java Script
• JavaScript was designed to add interactivity to HTML pages
• JavaScript is a scripting language • A scripting language is a lightweight programming
language • A JavaScript consists of lines of executable
computer code • A JavaScript is usually embedded directly into
HTML pages • JavaScript is an interpreted language (means that
scripts execute without preliminary compilation) • Everyone can use JavaScript without purchasing a
license
04/11/23 Free template from www.brainybetty.com 14
Java Script Basic
• Most of syntax same as JAVA
• Some JAVA feature was cut out e.g. public protected static etc.
• Case sensitive
• Interpreted language not compiled language
• Flexible data type
04/11/23 Free template from www.brainybetty.com 15
Variables
• Syntax examplevar strname = "Hege"
• Variable scope– Local: declared within a function– Global: elsewhere
• Overriding global variable
• Implicit declaration
04/11/23 Free template from www.brainybetty.com 16
Arithmetic Operators
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (division remainder)
++ Increment
-- Decrement
04/11/23 Free template from www.brainybetty.com 17
Assignment Operators
Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y x=x%y
04/11/23 Free template from www.brainybetty.com 18
Comparison Operators
Operator Description
== is equal to
=== is equal to (checks for both value and type)
!= is not equal
> is greater than
< is less than
>= is greater than or equal to
<= is less than or equal to
04/11/23 Free template from www.brainybetty.com 19
Flow control
• If then else
• Switch
• For loop
• While loop
• Break/continue statement
04/11/23 Free template from www.brainybetty.com 20
Arrays
• Creating an arrayvar mycars=new Array();
var mycars=new Array(3);
var mycars=new Array("Saab","Volvo","BMW");
• Accessing value in arrayalert(mycars[0] );
• Dynamic length
• Flexible data type
04/11/23 Free template from www.brainybetty.com 21
Basic Function
• alert(“some text”);
• confirm(“some text”);– Return true/false
• prompt(“some text”,”default value”);– Return user’s inputted value
04/11/23 Free template from www.brainybetty.com 22
Java Script ObjectObject Description
Window The top level object in the JavaScript hierarchy. The Window object represents a browser window. A Window object is created automatically with every instance of a <body> or <frameset> tag
Navigator Contains information about the client's browser
Screen Contains information about the client's display screen
History Contains the visited URLs in the browser window
Location Contains information about the current URL
04/11/23 Free template from www.brainybetty.com 23
Events
• Examples of events:– A mouse click – A web page or an image loading – Mousing over a hot spot on the web
page – Selecting an input box in an HTML form – Submitting an HTML form – A keystroke
04/11/23 Free template from www.brainybetty.com 24
HTML Event
• onload and onUnload• onFocus, onBlur and onChange• onSubmit• onMouseOver and onMouseOut• And etc.
• Invoking Java Script function<input type="text" size="30" id="email"
onchange="checkEmail()">
04/11/23 Free template from www.brainybetty.com 25
HTML DOMThe DOM (Document Object Model) presents an HTML document as a tree-structure (a node tree), with elements, attributes, and text.
04/11/23 Free template from www.brainybetty.com 26
DOM Inspector
04/11/23 Free template from www.brainybetty.com 27
Access Node
• Get element by IDdocument.getElementById('someID')
• Get element by tag namedocument.getElementsByTagName("p")
• Return value possible to be either object or array of object
• parentNode, firstChild, lastChild and etc.
04/11/23 Free template from www.brainybetty.com 28
Question & Answer