1 / 13

JavaScript Coding

JavaScript Coding. HTML DOM, functions, control structures. HTML with JavaScript. With the object model, JavaScript gets all the power it needs to create dynamic HTML: JavaScript can change all the HTML elements in the page. JavaScript can change all the HTML attributes in the page.

fmcgovern
Télécharger la présentation

JavaScript Coding

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaScript Coding HTML DOM, functions, control structures

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

  3. Document Object Model The DOM is a W3C (World Wide Web Consortium) standard for accessing documents. "The W3C 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 W3C 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 - standard model for HTML documents

  4. 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.

  5. 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.

  6. Finding HTML Elements Often, with JavaScript, you want to manipulate HTML elements. To do so, you have to find the elements first. There are 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

  7. JavaScript 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

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

  9. Loops Loops can execute a block of code as long as a specified condition is true. JavaScript 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 specified condition is true.

  10. Break and Continue • break and continue are JavaScript 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.

  11. Functions • A JavaScript function is a block of code designed to perform a particular task. A JavaScript function is executed when it’s invoked. • A JavaScript 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: (parameter1, parameter2, ...) • The code to be executed is placed inside curly brackets: {}

  12. 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 JavaScript code • Automatically (self invoked)

  13. Function Return • When JavaScript reaches a return statement, the function will stop executing. • If the function was invoked from a statement, JavaScript 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".

More Related