Part 2 - Client side JavaScript and the DOM Flashcards
gives access to all the images in a document.
describe the following
window.document.images
describe the following
window.location.pathname
will return the path of the current page
the javascript is:
document.getElementById("tt284").innerHTML = "<h2>Hello World</h2>"
write the javascript that will:
get the element with id “tt284” and then replace its nested content with a h2 header that says “hello world”
insert a javascript alert using an HTML script element
code:
<script> alert("JavaScript is working in your browser"); </script>
describe the
window.location
object
this is an object that has properties and methods that can display addrees, protocol and port information of the page and even redirect a page
give 2 benefits of a
thick client
Benefits:
* Operations no longer require a HTTP request to the server giving speed improvements and less waiting for the user
* Easier to deliver an application via a thick client than developing for different machines with different environments
describe the dom method
querySelectorAll()
Accesses all child elements matching a CSS selector
Accesses all child elements matching a CSS selector
describe the dom method
querySelectorAll()
this is a structure built by web browser from a given HTML document.
it is how the browser views and represent a page
what is the
document object model (DOM)
write the code that will import a javascript file
code:
<script src="path/to/file.js"></script>
what is the js code that
create a new HTML element and hold it inside a variable
the code is:var buttonElement = document.createElement("button");
converts a value to a number.
If the value cannot be converted,NaNis returned.
describe the javascript method
number()
give two drawbacks of javascripts
innerHTML
drawbacks include:
1.Screen readers may not be aware of the new content
2.Care must be taken when adding untrusted data in case it is malicious
these include:
1. Ad blockers - used to block ads
2. Reference management tools - which help collect and mange reference material for research
3. Bookmarking - allowing users to collect and annotate content
give 3 examples of adding functionality to a web browser
describe the following
window.document.forms
gives access to all the forms in a document.
describe the javascript method
toFixed()
method converts a number to a string and rounds the string to a specified number of decimals.
describe the
window.navigator
object
this is an object that will hold details of the users browser
software will use these so that they can access, read and modify there nodes
this means that dynamic content can be created
how does software take advantage of the:
Document Object Model (DOM)
and
Browser Object Model (BOM)
Accesses all child elements with a specified tagname
describe the dom method
getElementsByTagName()
describe the following
window.document.characterSet
this will access and return the character encoding for the document
this object contains the browsers history
describe the
window.history
object
code:
<script> alert("JavaScript is working in your browser"); </script>
insert a javascript alert using an HTML script element
this is similar to the Document Object Model (DOM) in that it is a structure that is built by the browser.
however this will instead expose parts of the web browser instead of the HTML document
what is the
Browser Object Model (BOM)
drawbacks include:
1.Screen readers may not be aware of the new content
2.Care must be taken when adding untrusted data in case it is malicious
give two drawbacks of javascripts
innerHTML
how does software take advantage of the:
Document Object Model (DOM)
and
Browser Object Model (BOM)
software will use these so that they can access, read and modify there nodes
this means that dynamic content can be created
write the code that will create a javascript alert when a hyperlink is clicked
code:
<a href="javascript:alert('JavaScript is working in your browser');">link</a>
these include:
* .length - returns the number of URLs in the history list.
* .back() - mimics clicking back in the browser
* .forward() - mimics clicking forward in the browser
give 3 methods that belong to the
window.history object
method converts a number to a string and rounds the string to a specified number of decimals.
describe the javascript method
toFixed()
describe the following terms related to the Document Object Model (DOM) :
1. node
2. root
3. parent
4. child
5. sibling
6. object
- node - is a single element of the Document Object Model (DOM)
- root - is the starting point of the DOM, which is the document node
- parent - a node that has children (nested nodes)
- child - a node that belongs to a parent (is nested within a node)
- sibling - nodes that share the same parent
- object - is a node plus all of its children and descendents
how does a
thick client
operate
this will take on many processing tasks and will most likely be relieveing those tasks from the server.
however initial data may be required from the server so that it can perform operations on that data
the code is:var buttonElement = document.createElement("button");
what is the js code that
create a new HTML element and hold it inside a variable
these include:
* plug-ins
* add ons
* extensions
what 3 things do most web browsers support that give them additional functionality
give 4 points that contribute to javascript being so dominant
these include:
1. JavaScript can be embedded in any HTML page.
2. JavaScript can be natively interpreted by all modern browsers, without the use of any extensions or plug-ins.
3. Computations and actions can be executed on the client side, and there are situations in which this is preferred, for example to provide immediate responsiveness in a web page.
4. JavaScript is ‘mainstream’, meaning that it is recognised as a useful language with many practitioners. It is recognised as an evolving standard known as ECMAScript and as having some longevity.
describe the
window.document
object
this is the HTML document that has been turned into an object with methods and properties by the browser
give a benefit and disadvantage of a
thin client
Benefit - the software and hardware can be relatively simple as little work is needed
Disadvantage - Because these do no processing operations may take longer as HTTP request must be made to the server and there is also the processing time of the server
the code is:var textElement = document.createTextNode("My new TT284 button");
what is the js code to
create a text node and hold it in a variable
describe the following
window.navigator.appVersion
this will retrieves the browser version
Benefit - the software and hardware can be relatively simple as little work is needed
Disadvantage - Because these do no processing operations may take longer as HTTP request must be made to the server and there is also the processing time of the server
give a benefit and disadvantage of a
thin client
describe the dom method
**querySelector() **
Accesses the first child element matching a CSS selector