Save
Mobile & Web Development
Week3
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
Khin Htet Htet Htar
Visit profile
Cards (57)
Document Object Model (DOM)
The data representation of the objects that comprise the structure and
content
of a document on the
web
View source
The DOM represents the page so that programs can change the document
structure
,
style
, and content
View source
The DOM represents the document as
nodes
and objects so that programming languages can
connect
to the page
View source
JavaScript
An
interpreted language
(with
JIT
support) where each browser has its own JavaScript engine which executes our Client-side scripts
View source
"Browser Wars" have ensued in recent years, resulting in a vast increase in the
performance
of Client-side JavaScript
View source
JavaScript Engines
Google Chrome
-
V8 Engine
Microsoft Edge
-
Chakra Engine
Mozilla Firefox
-
Spidermonkey Engine
Apple Safari
- JavaScript Core (
Nitro
)
View source
Client-side scripting
Allows us to create more
responsive
web applications
View source
Major uses of Client-side JavaScript
Responding
to UI events (clicks, hovers, focus)
Client-side
validation
(e.g.
form
processing)
Injecting/Modifying HTML content on the fly using the DOM
Dynamically
changing the
look
/feel of HTML elements by controlling the CSS styling
Animations/
Fades
/
Transitions
View source
What JavaScript can do
Change all the
HTML
elements in the page
Change all the HTML
attributes
in the page
Change all the
CSS
styles in the page
Remove
existing HTML
elements and
attributes
Add new
HTML
elements and attributes
React to all
existing HTML
events in the page
Create new HTML events in the page
View source
JavaScript data types
Core data types: number,
string
, Boolean,
array
, object, function
Browser/DOM types: Document, Event,
HTMLElement
,
Window
User-defined
types
View source
JavaScript is a
dynamically
typed
language
View source
We include our JavaScript
libraries
first, and then any custom
JS
file(s)
View source
Ways to access HTML elements with JavaScript
Finding by
id
Finding by
tag
name
Finding by
class
name
Finding by
CSS
selectors
View source
querySelector and querySelectorAll
Newer
,
all-in-one
methods to select elements
View source
DOM Manipulation using JavaScript (EVENTS)
1.
getAttribute()
2.
setAttribute()
3.
appendChild()
4.
append()
5.
prepend()
6.
removeChild()
7.
remove()
8.
createElement()
9.
innerText
10. innerHTML
11.
style
12.
value
View source
JavaScript runs inside a
sandbox
, so it has
limited
access to our machine resources
View source
Resources JavaScript has access to
Window
Navigator
Screen
Location
View source
JavaScript Display Possibilities
Writing into an
HTML element
, using
innerHTML
Writing into the HTML
output
using
document.write()
Writing into an
alert
box, using
window.alert()
Writing into the browser console, using
console.log()
View source
JQuery
A JavaScript Library that simplifies DOM Traversal,
searching
and
manipulation
View source
Document.ready function
Prevents code
from executing
before
the initial DOM has been built
View source
$() function
Represents a selector in the same way as querySelector or
getElementByID
View source
Useful JQuery
Selectors
$("p") - select all paragraphs
$("img") - select all images
$(".anExample") - select all
HTML
elements using
class
"anExample"
$("#yetAnother") - select the
HTML element
with id "
yetAnother
"
View source
Features
DOM
Selection
DOM
Manipulation
Special
Effects
Event
Handling
AJAX
Cross
browser support
View source
DOM Selection
Provide
selectors
to
retrieve
DOM elements
View source
DOM Manipulation
Manipulate DOM elements using various jQuery functions: adding or
removing
elements,
modifying
html/css contents
View source
Special
Effects
Show/
Hide
elements, fade-in/out,
sliding
, animations
View source
Event Handling
Include
functions
for
DOM
events
View source
AJAX
Includes
AJAX
functions to
load data
from server without reloading whole page
View source
The major feature of jQuery is the simplification of DOM Traversal,
searching
and
manipulation
, using its $ syntax
View source
Document.ready function
The
starting point
for all jQuery code to be integrated into your website (whether its Static or Dynamic, jQuery
doesn't
care...)
View source
Useful jQuery
Selectors
$("p") - select all paragraphs
$("img") - select all images
$(".anExample") - select all
HTML
elements using
class
"anExample"
$("#yetAnother") - select the
HTML element
which uses id "yetanother"
View source
DOM Manipulation Methods
text
()
html
()
val
()
attr
()
View source
text()
Sets or returns the text content of selected
elements
View source
html()
Sets or returns the content of selected elements (including
HTML markup
)
View source
val()
Sets or returns the value of
form
fields
View source
attr()
Used to get and set
attribute
values
View source
css
()
Sets or returns one or more style
properties
for the
selected
elements
View source
To return the value of a specified
CSS
property, use
css
("propertyname");
View source
To set a CSS Property, use
css
("
propertyname
","value");
View source
To set multiple CSS
Properties
, use
css
({"propertyname":"value","propertyname":"value",...});
View source
See all 57 cards