Java Script Coding HTML DOM functions control structures

  • Slides: 13
Download presentation
Java. Script Coding HTML DOM, functions, control structures

Java. Script Coding HTML DOM, functions, control structures

HTML with Java. Script With the object model, Java. Script gets all the power

HTML with Java. Script With the object model, Java. Script gets all the power it needs to create dynamic HTML: ● Java. Script can change all the HTML elements in the page. ● Java. Script can change all the HTML attributes in the page. ● Java. Script can change all the CSS styles in the page. ● Java. Script can remove existing HTML elements and attributes. ● Java. Script can add new HTML elements and attributes. ● Java. Script can react to all existing HTML events in the page.

Document Object Model The DOM is a W 3 C (World Wide Web Consortium)

Document Object Model The DOM is a W 3 C (World Wide Web Consortium) standard for accessing documents. "The W 3 C Document Object Model (DOM) is a platform and language -neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document. " The W 3 C DOM standard is separated into 3 different parts: ● Core DOM - standard model for all document types ● XML DOM - standard model for XML documents

HTML DOM The HTML DOM is a standard object model and programming interface for

HTML DOM The HTML DOM is a standard object model and programming interface for HTML. It defines: ● The HTML elements as objects. ● The properties of all HTML elements. ● The methods to access all HTML elements. ● The events for all HTML elements. In other words: The HTML DOM is a standard for how to get, change, add, or delete HTML elements.

HTML DOM Document In the HTML DOM object model, the document object represents your

HTML DOM Document In the HTML DOM object model, the document object represents your web page and is the owner of all other objects in your web page. If you want to access objects in an HTML page, you always start with accessing the document object. It can be used to: ● Find, change, add and delete HTML elements. ● Find HTML Objects. ● Add event handlers.

Finding HTML Elements Often, with Java. Script, you want to manipulate HTML elements. To

Finding HTML Elements Often, with Java. Script, you want to manipulate HTML elements. To do so, you have to find the elements first. There a couple of ways to do this: ● Finding HTML elements by id ● Finding HTML elements by tag name ● Finding HTML elements by class name ● Finding HTML elements by HTML object collections

Java. Script Control Structures Control structures are used when we want control to take

Java. Script Control Structures Control structures are used when we want control to take a particular path through the code, depending on certain conditions. Control structures include branches, cases and loops

Conditional Statements Conditional statements are used to perform different actions based on different conditions.

Conditional Statements Conditional statements are used to perform different actions based on different conditions. Include if, if - else ladders and switch. See examples for syntax.

Loops can execute a block of code as long as a specified condition is

Loops can execute a block of code as long as a specified condition is true. Java. Script supports different kinds of loops: ● for - loops through a block of code a number of times. ● for/in - loops through the properties of an object. ● while - loops through a block of code while a specified condition is true. ● do/while - also loops through a block of code while a

Break and Continue ● break and continue are Java. Script keywords used to manipulate

Break and Continue ● break and continue are Java. Script keywords used to manipulate the loop iterations. ● The break statement "jumps out" of a loop. ● The continue statement "jumps over" one iteration in the loop.

Functions ● A Java. Script function is a block of code designed to perform

Functions ● A Java. Script function is a block of code designed to perform a particular task. A Java. Script function is executed when it’s invoked. ● A Java. Script function is defined with the function keyword, followed by a name, followed by parentheses (). ● Function names can contain letters, digits, underscores, and dollar signs. ● The parentheses may include parameter names separated by commas: (parameter 1, parameter 2, . . . )

Function Invocation The code inside the function will execute when "something" invokes (calls) the

Function Invocation The code inside the function will execute when "something" invokes (calls) the function: ● When an event occurs (when a user clicks a button) ● When it is invoked (called) from Java. Script code ● Automatically (self invoked)

Function Return ● When Java. Script reaches a return statement, the function will stop

Function Return ● When Java. Script reaches a return statement, the function will stop executing. ● If the function was invoked from a statement, Java. Script will "return" to execute the code after the invoking statement. ● Functions often compute a return value. The return value is "returned" back to the "caller".