EECS1012. Net-centric Introduction to Computing. Lecture JavaScript DOM
|
|
- Kristin McDowell
- 6 years ago
- Views:
Transcription
1 EECS 1012 Net-centric Introduction to Computing Lecture JavaScript DOM Acknowledgements Contents are adapted from web lectures for Web Programming Step by Step, by M. Stepp, J. Miller, and V. Kirst. Slides have been ported to PPT by Dr. Xenia Mountrouidou. These slides have been edited for, York University. The contents of these slides may be modified and redistributed, please give appropriate credit. M.S. Brown, EECS York University 1 (Creative Commons) Michael S. Brown, 2017.
2 2 A bit more on JavaScript
3 Array length 3 function myfunction { } var a = ["apple", "banana", "kiwi", "cherry", "orange"]; var len = a.length; // variable len will be 5 Like JS strings, arrays have a built in length property we can access using the ".length" operator In PHP, you needed to call the function count($array) to get its size
4 Variable "scope" 4 function myfunction { var a = 10; /* these variables are only valid inside this var b = 20; function. we say their scope is limited var c = a * b; to this function. We call this local scope. */ } function myfunction2 { var a = 100; /* variable a here is a different a than the the function above. Variable b and c are undefined in this function. */ } Variables can have two types of "scope". Local scope means a variable is only available inside a function Global scope means a variable is available in all functions (see next slide)
5 JS code and global variables 5 /* Code is run as soon as loaded these variables are created */ var classname = ""; /* This is a global variable */ var intcounter = 0; /* This is another global variable */ function myfunction { var Name = document.getelementbyid("header1"); Name.innerHTML += classname; /* classname can be used in any function */ int Counter++; /* intcounter can be used here */ } JS code is run immediately when the file is loaded Variables defined outside functions are consider "Global" variables. These variables can be used by any function. There values will be remembers between function calls.
6 Loading multiple JS files 6 Like CSS, you can load multiple JS files in your header <!DOCTYPE html> <html> <head> <script src=" type="text/javascript"></script> <script src="example.js" type="text/javascript"></script> </head> <body>... </body> </html> This is a URL to a JS file. The second is a local JS file.
7 Multiple JS functions 7 Your JS files can have multiple functions function fun1() { /* function 1 and its code */ statements; statements; } function fun2() { /* function2 and its code */ statements; statements; } function fun3() { /* function3 and its code */ statements; statements; }
8 8 Global DOM objects
9 Global DOM objects 9 Web browser provide six global objects that you can access in your JavaScript code These objects can be used to control the browsers and get information about the current webpage (and history)
10 The six global DOM objects 10 name document history location navigator screen window description current HTML page and its content list of pages the user has visited URL of the current HTML page info about the web browser you are using info about the screen area occupied by the browser the browser window In our class, we will mainly use the document object, however, it is good to be aware of these other global objects. They are discussed briefly in the following slides. EECS 1012
11 The location object 11 the URL of the current web page properties: host, hostname, href, pathname, port, protocol, search methods: assign, reload, replace EECS 1012
12 The screen object 12 information about the client's display screen properties: availheight, availwidth, colordepth, height, pixeldepth, width EECS 1012
13 The history object 13 the list of sites the browser has visited in this window properties: length methods: back, forward, go sometimes the browser won't let scripts view history properties, for security EECS 1012
14 The document object 14 the current web page and the elements inside it properties: anchors, body, cookie, domain, forms, images, links, referrer, title, URL useful methods: getelementbyid() getelementsbyname() getelementsbytagname() EECS 1012
15 The window object 15 the entire browser window; the top-level object in DOM hierarchy technically, all global code and variables become part of the window object properties: document, history, location, name important method onload This method is called when the entire HTML document has completed loading
16 16 Unobtrusive JavaScript
17 Obtrusive event handlers 17 <button id="ok" onclick="okayclick();">ok</button> HTML We directly link "onlick" to our // called when OK button is clicked JS function "okayclick()". function okayclick() { This is considered "obtrusive". alert("booyah"); } JS this is bad style (HTML is cluttered with JS code) it requires the person writing the HTML code to know the JS code in advance GOAL: remove all JavaScript code from the HTML body
18 Why unobtrusive JavaScript? 18 Why do we want unobtrusive JS Code? allows separation of web site into 3 major categories: content (HTML) - what is it? presentation (CSS) - how does it look? behavior (JavaScript) - how does it respond to user interaction? EECS 1012
19 Attaching an event handler in JavaScript code 19 // where element is a DOM element object element.event = function; JS /* Example */ var button = document.getelementbyid("ok"); button.onclick = okayclick; /* <- LOOK: no() after func name*/ JS it is possible to attach event handlers to elements' DOM objects in your JavaScript code notice that you do not put parentheses after the function's name this is better style than attaching them in the HTML Where should we put the above code?
20 Remember: When does JS code run? 20 <head> <script src="myfile.js" type="text/javascript"></script> </head> <body>... </body> HTML // global code start running as soon as it is linked var x = 3; function f(n) { return n + 1; } function g(n) { return n - 1; } x = f(x); your file's JS code runs the moment the browser loads the script tag any variables are declared immediately any functions are declared but not called, unless your global code explicitly calls them JS
21 When does my code run? 21 <head> <script src="myfile.js" type="text/javascript"></script> </head> <body>... </body> HTML // global code start running as soon as it is linked var x = 3; function f(n) { return n + 1; } function g(n) { return n - 1; } x = f(x); at this point in time, the browser has not yet read your page's body EECS 1012 none of the DOM objects for tags on the page have been created JS
22 A failed attempt at being unobtrusive 22 <head> <script src="myfile.js" type="text/javascript"></script> </head> <body> <div><button id="ok">ok</button></div> HTML // global code var button = document.getdocumentbyid("ok"); button.onclick = okayclick; problem: global JS code runs the moment the script is loaded script in head is processed before page's body has loaded no elements are available yet or can be accessed yet via the DOM!! JS
23 Solution: the window.onload event 23 // this will run once the page has finished loading function functionname() { element.event = functionname1; element.event = functionname2;... } window.onload = functionname; // global code we want to attach our event handlers right after the page is done loading there is a global event called window.onload event that occurs at that moment in window.onload handler we attach all the other handlers to run when events occur JS
24 An unobtrusive event handler 24 <! look, no JavaScript! --> <button id="ok">ok</button> HTML // called when page loads; sets up event handlers function pageload() { var button = document.getelementbyid("ok"); button.onclick = okayclick; } function okayclick() { alert("booyah"); } In this example, we assign the event "okayclick" using JS code, instead of the HTML page. This is considered unobtrusive. window.onload = pageload; // global code JS EECS 1012
25 Common unobtrusive JS errors 25 window.onload = pageload(); /* remember - don't put the () */ window.onload = pageload; okbutton.onclick = okayclick(); okbutton.onclick = okayclick; JS Remember, when we assign in the names of function, don't use the (), only the function name. window.onload = pageload; /* <- the L is not capital */ window.onload = pageload; JS also, event names are all lowercase, not capitalized like other variables EECS 1012
26 Anonymous functions 26 /* look, no name! we call this an anonymous function */ function() { statements; } JS JavaScript allows you to declare anonymous functions quickly creates a function without giving it a name can be stored as a variable, attached as an event handler, etc. EECS 1012
27 Anonymous function example 27 /* the example below is an anonymous function, notice there is no name given to this function. However, the function is only called once when the "window.onload" even occurs, so it is OK we don't give it name */ window.onload = function() { var okbutton = document.getelementbyid("ok"); okbutton.onclick = okayclick; }; function okayclick() { alert("booyah"); } We set window.onload = to an anonymous function. JS EECS 1012
28 Revisit example from last lecture 28 The HTML code below has an explicit link to "onclick" in it (i.e. obtrusive JS) <input id="num1" type="text" size="3"> + <input id="num2" type="text" size="3"> = <span id="answer"></span> <br> <button onclick="compute();">compute!</button> function compute() { var input1 = document.getelementbyid("num1"); var input2 = document.getelementbyid("num2"); var answer = document.getelementbyid("answer"); var result = input1.value + input2.value; answer.innerhtml = result; } This example is considered obtrusive, because we had to define the onlick event in the HTML. This means the HTML page needs to know about the JS file and function names, etc.
29 Unobtrusive version 29 <input id="num1" type="text" size="3"> + <input id="num2" type="text" size="3"> = <span id="answer"></span> <br> <button id="compute">compute!</button> window.onload = pageload; function pageload() { var computebutton = document.getelementbyid("compute"); computebutton.onclick = compute; } function compute() { var input1 = document.getelementbyid("num1"); var input2 = document.getelementbyid("num2"); var answer = document.getelementbyid("answer"); var result = input1.value + input2.value; answer.innerhtml = result; } This is unobtrusive, only have to put an "id" for this button. The onclick event is linked from JS.
30 Version 2 with anonymous function 30 <input id="num1" type="text" size="3"> + <input id="num2" type="text" size="3"> = <span id="answer"></span> <br> <button id="compute">compute!</button> window.onload = function () { var computebutton = document.getelementbyid("compute"); computebutton.onclick = compute; } function compute() { var input1 = document.getelementbyid("num1"); var input2 = document.getelementbyid("num2"); var answer = document.getelementbyid("answer"); var result = input1.value + input2.value; answer.innerhtml = result; } This is unobtrusive, only have to put an "id" for this button. The onclick event is linked from JS. Here, the pageload() function has been replaced with an anonymous function.
31 Recap unobtrusive JS 31 Unobtrusive JS is general approach to JS programming that tries to avoid having JS code inside the HTML page When possible, try to write JS code in an unobtrusive manner Use the "windows.onload" event to assign all the event handlers
32 32 The DOM tree
33 The document object model 33 The DOM models the HTML elements as a "tree" structure A tree is a type of data structure common in computer science to organize data Consider the next slide's HTML code
34 Consider the following HTML page 34 <!DOCTYPE html> <html> <head> <title> Page Title </title> <meta name="description" content="a really great web site"> <meta charset="utf-8"> </head> <body> <h1> This is a heading </h1> <p> A paragraph with a <a href= link </a>.</p> <ul> <li>a list item</li> <li>another item</li> <li>a third item</li> </ul> </body> </html>
35 The DOM tree 35 This is the "tree" representation of the HTML page on the previous slide. EECS 1012
36 Tree terminology 36 Items in tree are called "nodes". Like a family tree, we have the notion of a "parent" and "child" nodes. For example, body is the parent of h1, p, and ul. h1, p, ul are child nodes of body. EECS 1012 The nodes at the end of the tree are called "leafs"
37 Types of DOM nodes 37 <p> This is a paragraph of text with a <a href="/path/page.html">link in it</a>. </p> HTML element nodes (HTML tag) can have children and/or attributes text nodes (text in a block element) attribute nodes (attribute/value pair) EECS 1012 text/attributes are children in an element node cannot have children or attributes not usually shown when drawing the DOM tree
38 Types of DOM nodes 38 <p> This is a paragraph of text with a <a href="/path/page.html">link in it</a>. </p> HTML Consider the DOM of a node. This is a "mini-tree" considering on the <p> element. It has three direct children: (1) a text node, (2) another element (link), and (3) another text node. (1) (2) (3) EECS 1012
39 Traversing the DOM tree 39 name(s) firstchild, lastchild *children nextsibling, previoussibling parentnode description start/end of this node's list of children array of all this node's children neighboring nodes with the same parent the element that contains this node We will do an example with the *children property. EECS 1012
40 DOM tree traversal example 40 <html> <head> <title> My page</title> <meta charset="utf-8"> <script src="dom_example1.js" type="text/javascript"></script> </head> <body> <h1>this is a Header</h1> <div id="mydiv"> <p> First paragraph </p> <p> Second paragraph </p> <p> Third paragraph </p> </div> <button id="button"> Click </button> </body> </html>
41 DOM tree traversal example 41 <body> <h1> This is a header </h1> <div id="mydiv"> <p> First paragraph </p> <p> 2 nd paragraph </p> <p> Third paragraph </p> <button> EECS 1012
42 DOM tree traversal example 42 <body> <h1> This is a header </h1> DOM Tree html <div id="mydiv"> title meta body <p> First paragraph </p> <p> 2 nd paragraph </p> h1 div <p> Third paragraph </p> p p p <button> This is drawn without the "text" elements, but each "p" has a text element that we can access using "innerhtml".
43 DOM tree traversal example 43 function walk() { var divelement = document.getelementbyid("mydiv"); var childelements = divelement.children; alert("mydiv element has " + childelements.length + " children"); for(var i=0; i < childelements.length; i++) { alert(childelements[i].innerhtml); } } returns an array with the children of div Gets the div element Loops through the array and prints (using alert) the innerhtml of the paragraph div p p p
44 Note: tree access 44 In the previous example, since we started with var divelement = document.getelementbyid("mydiv"); Our access to the DOM tree starts at div. As a result, we only had access to the "descendants" of div, not the full DOM tree div p p p You will see this word "descendants" in JS documentation
45 Selecting groups of DOM objects 45 methods in document and other DOM objects for accessing descendants: name getelementsbytagname getelementsbyname description returns array of descendants with the given tag, such as "div" returns array of descendants with the given name attribute (mostly useful for accessing form controls) EECS 1012
46 Getting all elements of a certain type 46 // all Paras is an array of element objects var allparas = document.getelementsbytagname("p"); // we loop trough all elements and change their background // to "yellow" for (var i = 0; i < allparas.length; i++) { allparas[i].style.backgroundcolor = "yellow"; } JS <body> <p>this is the first paragraph</p> <p>this is the second paragraph</p> <p>you get the idea...</p> </body> HTML EECS 1012 In tis example, we use the document object, so the descendants are all elements in the HTML page with tag name "p". This results
47 Previous code explained 47 var allparas = document.getelementsbytagname("p"); This will find all the DOM element objects that are <p> elements in the HTML page and return them as an array. This array is assigned to the variable "allparas". array index allparas = [ Paragraph, Paragraph, Paragraph ] Object (0) Object (1) Object (2) <body> <p>this is the first paragraph</p> <p>this is the second paragraph</p> <p>you get the idea...</p> </body> HTML
48 Previous code explained 48 Paragraph Object [i] allparas[i].style.backgroundcolor = "yellow"; allparas is an array of element objects. allparas[i] access the ith element in the array..style accesses the style component of the element object..backgroundcolor accesses the backgroundcolor property of the style component. Changes the background to yellow. So, this statement is accessing a single element object. The element accessed depends on the value of the variable i. <body> </body> <p>this is the first paragraph</p> <p>this is the second paragraph</p> <p>you get the idea...</p>
49 Combining with getelementbyid() 49 var addressdiv = document.getelementbyid("address"); var addrparas = addressdiv.getelementsbytagname("p"); for (var i = 0; i < addrparas.length; i++) { addrparas[i].style.backgroundcolor = "yellow"; } JS <p>this won't be returned!</p> <div id="address"> <p>1234 Street</p> <p>atlanta, GA</p> </div> HTML In this example, only the paragraphs contained within "addressdiv" are called. This is because "getelementsbytagname("p") is called from the div element. EECS 1012
50 50 Creating and Deleting Elements
51 Creating new nodes 51 name document.createelement("tag") document.createtextnode("text") description creates and returns a new empty DOM node representing an element of that type creates and returns a text node containing given text // create a new <h2> node var newheading = document.createelement("h2"); newheading.innerhtml = "This is a heading"; newheading.style.color = "green"; JS merely creating a node does not add it to the page you must add the new node as a child of an existing element on the page...
52 Modifying the DOM tree 52 name appendchild (node) insertbefore(new, old) removechild(node) replacechild(new, old) description places given node at end of this node's child list places the given new node in this node's child list just before old child removes given node from this node's child list replaces given child with new node var div = document.getelementbyid("mydiv"); var p = document.createelement("p"); p.innerhtml = "A paragraph!"; div.appendchild(p); /* append ads JS EECS 1012 This would add a new paragraph to div with id=mydiv.
53 Example adding items 53 <html> <head> <title> My page</title> <meta charset="utf-8"> <script src="dom_example5.js" type="text/javascript"></script> </head> <body> <p>to Do List</p> <input type="text" id="texttoadd" size="20"><br> <button id="button"> Click to Add Item</button> <ol id="list"> </ol> </body>
54 Example adding items 54 window.onload = function() { /* This finds the button and sets the onclick function */ var button = document.getelementsbytagname("button"); button[0].onclick = insertitem; } function insertitem() { var todolist = document.getelementbyid("list"); /* get list element */ var texttoadd = document.getelementbyid("texttoadd"); /* get text input element */ if (texttoadd.value!= "") /* if text input value isn't empty */ { var newli = document.createelement("li"); /* create a new li element */ newli.innerhtml = texttoadd.value; /* set the innerhtml to the text input value */ todolist.appendchild(newli); /* add this to the DOM tree */ /* by appending to the list object */ } }
55 Example delete items 55 <html> <head> <title> My page</title> <meta charset="utf-8"> <script src="dom_example4.js" type="text/javascript"></script> </head> <body> <p>to Do List</p> <button id="button"> Click Remove Item</button> <ol id="mylist"> <li> Study </li> <li> Call mom </li> <li> Pay rent </li> <li> Return library book </li> </ol> </body>
56 Example deleting items 56 window.onload = function() { /* attaches the deletelistitem function to the button */ var button = document.getelementsbytagname("button"); button[0].onclick = deletelistitem; } function deletelistitem() { var mylist = document.getelementbyid("mylist"); /* get list element */ var pars = mylist.getelementsbytagname("li"); /* get all li elements in the list element */ if (pars.length > 0) /* pars (array of li elements) is not 0 */ { mylist.removechild(pars[0]); /* remove the first li element from the */ } /* list element */ }
57 57 Prototype Library
58 Problem with JavasScript 58 JavaScript is a powerful language, but it has many flaws DOM can be clunky to use the same code doesn't work the same way on some browsers as a result, some developers have created a "library" (set of JS functions) call the "Prototype" library
59 Prototype Library 59 <script src=" type="text/javascript"></script> Prototype JS library adds many useful features to JS Makes DOM easier to use improves event-driven programming works the same across many browsers To use the Prototype library, link to it as shown above Note this access the JS file as a URL
60 Prototype framework 60 <script src=" ototype.js " type="text/javascript"></script> JS the Prototype JavaScript library adds many useful features to JavaScript: EECS 1012 many useful extensions to the DOM added methods to String, Array, Date, Number, Object improves event-driven programming many cross-browser compatibility fixes makes Ajax programming easier (seen later)
61 The $ function 61 $("id") returns the DOM object representing the element with the given id short for document.getelementbyid("id") often used to write more concise DOM code: JS $("footer").innerhtml = $("username").value; JS EECS 1012
62 Example with prototype 62 <html> dom_example6.html <head> <script src=" " type="text/javascript"></script> <script src="dom_example6.js" type="text/javascript"></script> </head> <body> <h1>the Amazing Adder</h1> <div> <input id="num1" type="text" size="3"> + <input id="num2" type="text" size="3"> = <span id="answer"></span> <br> <button onclick="compute();">compute!</button> </div> </body> </html> dom_example6.js function compute() { var num1 = $("num1").value; var num2 = $("num2").value; $("answer").innerhtml = parseint( num1 ) + parseint( num2 ); }
63 Prototype 63 HTML (note: this example is obtrusive HTML.. but the purpose of this example is to who the prototype library in JS) <input id="num1" type="text" size="3"> + <input id="num2" type="text" size="3"> = <span id="answer"></span> <br> <button onclick="compute();">compute!</button> Using the $("element_id") we have function compute() { much more compact JS code. It is var num1 = $("num1").value; also easier to make the connection var num2 = $("num2").value; back to the HTML page. $("answer").innerhtml = parseint( num1 ) + parseint( num2 ); } $("id") is equivalent to calling document.getelementbyid("id").
64 Recap 64 The DOM gives JS access to the underlying webpage The DOM tree is used to describe the HTML page This gives us the ability to modify, create, and delete elements in the tree (i.e. HTML page) The prototype library makes accessing document elements "cleaner" We will use the prototype library more in the next lecture on "events".
EECS1012. Net-centric Introduction to Computing. Lecture JavaScript DOM
EECS 1012 Net-centric Introduction to Computing Lecture JavaScript DOM Acknowledgements Contents are adapted from web lectures for Web Programming Step by Step, by M. Stepp, J. Miller, and V. Kirst. Slides
More informationRecall: Document Object Model (DOM)
Page 1 Document Object Model (DOM) CSE 190 M (Web Programming), Spring 2007 University of Washington References: Forbes/Steele, Chipman (much of this content was stolen from them) Recall: Document Object
More informationWeb Programming Step by Step
Web Programming Step by Step Lecture 15 Unobtrusive JavaScript Reading: 8.1-8.3 Except where otherwise noted, the contents of this presentation are Copyright 2009 Marty Stepp and Jessica Miller. 8.1: Global
More informationCSE 154 LECTURE 10: THE DOM TREE
CSE 154 LECTURE 10: THE DOM TREE The keyword this this.fieldname // access field this.fieldname = value; // modify field this.methodname(parameters); // call method JS all JavaScript code actually runs
More informationWeb Programming Step by Step
Web Programming Step by Step Lecture 16 The DOM Tree Reading: 8.3, 9.1 Except where otherwise noted, the contents of this presentation are Copyright 2009 Marty Stepp and Jessica Miller. Complex DOM manipulation
More information1 The DOM tree CS380
1 The DOM tree The DOM tree 2 Types of DOM nodes 3 This is a paragraph of text with a link in it. HTML element nodes (HTML tag) can have children and/or attributes
More informationUnobtrusive JavaScript. Lecture Outline. CSE 190 M (Web Programming), Spring 2008 University of Washington
Unobtrusive JavaScript CSE 190 M (Web Programming), Spring 2008 University of Washington Except where otherwise noted, the contents of this presentation are Copyright 2008 Marty Stepp and Jessica Miller
More informationWalking the DOM Tree. Lecture Outline. An example XHTML page. CSE 190 M (Web Programming), Spring 2008 University of Washington
Walking the DOM Tree CSE 190 M (Web Programming), Spring 2008 University of Washington References: Forbes/Steele, Chipman (much of this content was stolen from them) Except where otherwise noted, the contents
More informationEECS1012. Net-centric Introduction to Computing. Lecture Introduction to Javascript
EECS 1012 Net-centric Introduction to Computing Lecture Introduction to Javascript Acknowledgements Contents are adapted from web lectures for Web Programming Step by Step, by M. Stepp, J. Miller, and
More informationJavascript. Many examples from Kyle Simpson: Scope and Closures
Javascript Many examples from Kyle Simpson: Scope and Closures What is JavaScript? Not related to Java (except that syntax is C/Java- like) Created by Brendan Eich at Netscape later standardized through
More informationEECS1012. Net-centric Introduction to Computing. Lecture "Putting It All Together" and a little bit of AJAX
EECS 1012 Net-centric Introduction to Computing Lecture "Putting It All Together" and a little bit of AJAX Acknowledgements The contents of these slides may be modified and redistributed, please give appropriate
More informationWeb Programming Step by Step
Web Programming Step by Step Lecture 14 DOM and Timers Reading: 7.2-7.3; 8.2; 9.2.6 Except where otherwise noted, the contents of this presentation are Copyright 2009 Marty Stepp and Jessica Miller. Problems
More informationCSc 337 LECTURE 6: JAVASCRIPT
CSc 337 LECTURE 6: JAVASCRIPT Client-side scripting client-side script: code runs in browser after page is sent back from server often this code manipulates the page or responds to user actions What is
More informationBest Practices Chapter 5
Best Practices Chapter 5 Chapter 5 CHRIS HOY 12/11/2015 COMW-283 Chapter 5 The DOM and BOM The BOM stand for the Browser Object Model, it s also the client-side of the web hierarchy. It is made up of a
More informationJavaScript 3. Working with the Document Object Model (DOM) and DHTML
JavaScript 3 Working with the Document Object Model (DOM) and DHTML Objectives When you complete this lesson, you will be able to: Access elements by id, tag name, class, name, or selector Access element
More informationEECS1012. Net-centric Introduction to Computing. Lecture 3: CSS for Styling
EECS1012 Net-centric Introduction to Computing Lecture 3: CSS for Styling Acknowledgements Contents are adapted from web lectures for Web Programming Step by Step, by M. Stepp, J. Miller, and V. Kirst.
More informationjquery CS 380: Web Programming
jquery CS 380: Web Programming What is jquery? jquery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.
More informationINLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT
INLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT ME152A L4: 1. HIGHER ORDER FUNCTIONS 2. REGULAR EXPRESSIONS 3. JAVASCRIPT - HTML 4. DOM AND EVENTS OUTLINE What
More informationCIS 228 (Spring, 2012) Final, 5/17/12
CIS 228 (Spring, 2012) Final, 5/17/12 Name (sign) Name (print) email I would prefer to fail than to receive a grade of or lower for this class. Question 1 2 3 4 5 6 7 8 9 A B C D E TOTAL Score CIS 228,
More informationCSI 3140 WWW Structures, Techniques and Standards. Browsers and the DOM
CSI 3140 WWW Structures, Techniques and Standards Browsers and the DOM Overview The Document Object Model (DOM) is an API that allows programs to interact with HTML (or XML) documents In typical browsers,
More informationCE212 Web Application Programming Part 2
CE212 Web Application Programming Part 2 22/01/2018 CE212 Part 2 1 JavaScript Event-Handlers 1 JavaScript may be invoked to handle input events on HTML pages, e.g.
More informationXML: a "skeleton" for creating markup languages you already know it! <element attribute="value">content</element> languages written in XML specify:
1 XML What is XML? 2 XML: a "skeleton" for creating markup languages you already know it! syntax is identical to XHTML's: content languages written in XML specify:
More informationXML CSC 443: Web Programming
1 XML CSC 443: Web Programming Haidar Harmanani Department of Computer Science and Mathematics Lebanese American University Byblos, 1401 2010 Lebanon What is XML? 2 XML: a "skeleton" for creating markup
More informationAs we design and build out our HTML pages, there are some basics that we may follow for each page, site, and application.
Extra notes - Client-side Design and Development Dr Nick Hayward HTML - Basics A brief introduction to some of the basics of HTML. Contents Intro element add some metadata define a base address
More informationEECS1012. Net-centric Introduction to Computing. Lecture 5: Yet more CSS (Float and Positioning)
EECS 1012 EECS1012 Net-centric Introduction to Computing Lecture 5: Yet more CSS (Float and Positioning) Acknowledgements Contents are adapted from web lectures for Web Programming Step by Step, by M.
More informationUnderstanding this structure is pretty straightforward, but nonetheless crucial to working with HTML, CSS, and JavaScript.
Extra notes - Markup Languages Dr Nick Hayward HTML - DOM Intro A brief introduction to HTML's document object model, or DOM. Contents Intro What is DOM? Some useful elements DOM basics - an example References
More information5/19/2015. Objectives. JavaScript, Sixth Edition. Understanding the Browser Object Model and the Document Object Model. Objectives (cont'd.
Objectives JavaScript, Sixth Edition Chapter 5 Working with the Document Object Model (DOM) and DHTML When you complete this chapter, you will be able to: Access elements by id, tag name, class, name,
More informationJAVASCRIPT - CREATING A TOC
JAVASCRIPT - CREATING A TOC Problem specification - Adding a Table of Contents. The aim is to be able to show a complete novice to HTML, how to add a Table of Contents (TOC) to a page inside a pair of
More informationAJAX: The Basics CISC 282 March 25, 2014
AJAX: The Basics CISC 282 March 25, 2014 Synchronous Communication User and server take turns waiting User requests pages while browsing Waits for server to respond Waits for the page to load in the browser
More informationAJAX: The Basics CISC 282 November 22, 2017
AJAX: The Basics CISC 282 November 22, 2017 Synchronous Communication User and server take turns waiting User requests pages while browsing Waits for server to respond Waits for the page to load in the
More informationJavaScript: Events, DOM and Attaching Handlers
JavaScript: Events, DOM and Attaching Handlers CISC 282 October 11, 2017 Keyboard and Text Events Name The User Must Applicable Elements blur remove focus , ,... focus apply focus , ,...
More informationCOMP519 Web Programming Lecture 3: HTML (HTLM5 Elements: Part 1) Handouts
COMP519 Web Programming Lecture 3: HTML (HTLM5 Elements: Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of
More informationWeb Programming Step by Step
Web Programming Step by Step Lecture 20 XML Reading: 10.3-10.4 Except where otherwise noted, the contents of this presentation are Copyright 2009 Marty Stepp and Jessica Miller. What is XML? XML: a "skeleton"
More informationLING 408/508: Computational Techniques for Linguists. Lecture 16
LING 408/508: Computational Techniques for Linguists Lecture 16 Administrivia Homework 6 due next Monday Last Time Let's add an input field HTML: Input: enter
More informationEECS1012. Net-centric Introduction to Computing. Lecture JavaScript Events
EECS 1012 Net-centric Introduction to Computing Lecture JavaScript Events Acknowledgements Contents are adapted from web lectures for Web Programming Step by Step, by M. Stepp, J. Miller, and V. Kirst.
More informationJavaScript: Events, the DOM Tree, jquery and Timing
JavaScript: Events, the DOM Tree, jquery and Timing CISC 282 October 11, 2017 window.onload Conflict Can only set window.onload = function once What if you have multiple files for handlers? What if you're
More informationEECS1012. Net-centric Introduction to Computing. Lecture JavaScript and Forms
EECS 1012 Net-centric Introduction to Computing Lecture JavaScript and Forms Acknowledgements The contents of these slides may be modified and redistributed, please give appropriate credit. M.S. Brown,
More informationjquery Tutorial for Beginners: Nothing But the Goods
jquery Tutorial for Beginners: Nothing But the Goods Not too long ago I wrote an article for Six Revisions called Getting Started with jquery that covered some important things (concept-wise) that beginning
More informationHTML User Interface Controls. Interactive HTML user interfaces. Document Object Model (DOM)
Page 1 HTML User Interface Controls CSE 190 M (Web Programming), Spring 2007 University of Washington Reading: Sebesta Ch. 5 sections 5.1-5.7.2, Ch. 2 sections 2.9-2.9.4 Interactive HTML user interfaces
More informationCOMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2018)
COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2018) RAMANA ISUKAPALLI RAMANA@CS.COLUMBIA.EDU 1 LECTURE-1 Course overview See http://www.cs.columbia.edu/~ramana Overview of HTML Formatting, headings,
More informationCS7026. Introduction to jquery
CS7026 Introduction to jquery What is jquery? jquery is a cross-browser JavaScript Library. A JavaScript library is a library of pre-written JavaScript which allows for easier development of JavaScript-based
More informationProduced by. App Development & Modeling. BSc in Applied Computing. Eamonn de Leastar
App Development & Modeling BSc in Applied Computing Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie
More informationCOMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts
COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool
More informationAjax. Ronald J. Glotzbach
Ajax Ronald J. Glotzbach What is AJAX? Asynchronous JavaScript and XML Ajax is not a technology Ajax mixes well known programming techniques in an uncommon way Enables web builders to create more appealing
More informationExtensible Markup Language (XML) What is XML? An example XML file. CSE 190 M (Web Programming), Spring 2008 University of Washington
Extensible Markup Language (XML) CSE 190 M (Web Programming), Spring 2008 University of Washington Except where otherwise noted, the contents of this presentation are Copyright 2008 Marty Stepp and Jessica
More informationProgrammazione Web a.a. 2017/2018 HTML5
Programmazione Web a.a. 2017/2018 HTML5 PhD Ing.Antonino Raucea antonino.raucea@dieei.unict.it 1 Introduzione HTML HTML is the standard markup language for creating Web pages. HTML stands for Hyper Text
More informationData Visualization (DSC 530/CIS )
Data Visualization (DSC 530/CIS 602-01) HTML, CSS, & SVG Dr. David Koop Data Visualization What is it? How does it differ from computer graphics? What types of data can we visualize? What tasks can we
More informationJavaScript II CSCI 311 SPRING 2017
JavaScript II CSCI 311 SPRING 2017 Overview Look at more JavaScript functionality DOM slide show preloading images pull down menus and more! Document Object Model DOM gives us ways to access elements of
More informationJAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 6 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA
More informationDocument Object Model (DOM)
Document Object Model (DOM) Mendel Rosenblum Browser JavaScript interface to HTML document HTML document exposed as a collection of JavaScript objects and methods The Document Object Model (DOM) JavaScript
More informationCSC Javascript
CSC 4800 Javascript See book! Javascript Syntax How to embed javascript between from an external file In an event handler URL - bookmarklet
More informationExtensible Markup Language (XML) What is XML? Structure of an XML document. CSE 190 M (Web Programming), Spring 2007 University of Washington
Page 1 Extensible Markup Language (XML) CSE 190 M (Web Programming), Spring 2007 University of Washington Reading: Sebesta Ch. 8 sections 8.1-8.3, 8.7-8.8, 8.10.3 What is XML? a specification for creating
More informationReview of HTML. Chapter Pearson. Fundamentals of Web Development. Randy Connolly and Ricardo Hoar
Review of HTML Chapter 3 Fundamentals of Web Development 2017 Pearson Fundamentals of Web Development http://www.funwebdev.com - 2 nd Ed. What Is HTML and Where Did It Come from? HTML HTML is defined as
More informationUniversity of Washington, CSE 190 M Homework Assignment 8: Baby Names
University of Washington, CSE 190 M Homework Assignment 8: Baby Names This assignment is about using Ajax to fetch data from files and web services in text, HTML, XML, and JSON formats. You must match
More informationBridges To Computing
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited and encouraged to use this presentation to promote
More informationJavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore
JavaScript and XHTML Prof. D. Krupesha, PESIT, Bangalore Why is JavaScript Important? It is simple and lots of scripts available in public domain and easy to use. It is used for client-side scripting.
More informationUniversity of Washington, CSE 154 Homework Assignment 8: Baby Names
University of Washington, CSE 154 Homework Assignment 8: Baby Names This assignment is about using Ajax to fetch data in text, HTML, XML, and JSON formats. Every 10 years, the Social Security Administration
More informationWeb Development & Design Foundations with HTML5
1 Web Development & Design Foundations with HTML5 CHAPTER 14 A BRIEF LOOK AT JAVASCRIPT Copyright Terry Felke-Morris 2 Learning Outcomes In this chapter, you will learn how to: Describe common uses of
More informationDocument Object Model. Overview
Overview The (DOM) is a programming interface for HTML or XML documents. Models document as a tree of nodes. Nodes can contain text and other nodes. Nodes can have attributes which include style and behavior
More informationMake a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1
Make a Website A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1 Overview Course outcome: You'll build four simple websites using web
More informationData Visualization (CIS/DSC 468)
Data Visualization (CIS/DSC 468) Web Programming Dr. David Koop Definition of Visualization Computer-based visualization systems provide visual representations of datasets designed to help people carry
More information1. The basic building block of an HTML document is called a(n) a. tag. b. element. c. attribute. d. container. Answer: b Page 5
Name Date Final Exam Prep Questions Worksheet #1 1. The basic building block of an HTML document is called a(n) a. tag. b. element. c. attribute. d. container. Answer: b Page 5 2. Which of the following
More informationPlace User-Defined Functions in the HEAD Section
JavaScript Functions Notes (Modified from: w3schools.com) A function is a block of code that will be executed when "someone" calls it. In JavaScript, we can define our own functions, called user-defined
More informationHyper Text Markup Language
Hyper Text Markup Language HTML is a markup language. It tells your browser how to structure the webpage. HTML consists of a series of elements, which you use to enclose, or mark up different parts of
More informationJavaScript: Introduction to DOM and Attaching Handlers
JavaScript: Introduction to DOM and Attaching Handlers CISC 282 October 30, 2018 What Is DOM? Document Object Model An application programming interface (API) for HTML Set of objects, properties and methods
More informationCSC Web Programming. JavaScript Browser Objects
CSC 242 - Web Programming JavaScript Browser Objects JavaScript Object Types User defined objects Native objects (Array, Math, Date, etc.) Host Objects provided by the browser The window object is a representation
More informationProject 3 Web Security Part 1. Outline
Project 3 Web Security Part 1 CS155 Indrajit Indy Khare Outline Quick Overview of the Technologies HTML (and a bit of CSS) Javascript PHP Assignment Assignment Overview Example Attack 1 New to web programming?
More informationIntroduction to Web Development
Introduction to Web Development Lecture 1 CGS 3066 Fall 2016 September 8, 2016 Why learn Web Development? Why learn Web Development? Reach Today, we have around 12.5 billion web enabled devices. Visual
More informationClient Side JavaScript and AJAX
Client Side JavaScript and AJAX Client side javascript is JavaScript that runs in the browsers of people using your site. So far all the JavaScript code we've written runs on our node.js server. This is
More informationComp 426 Midterm Fall 2013
Comp 426 Midterm Fall 2013 I have not given nor received any unauthorized assistance in the course of completing this examination. Name: PID: This is a closed book exam. This page left intentionally blank.
More informationLA TROBE UNIVERSITY SEMESTER ONE EXAMINATION PERIOD. Subject Name: WEB DEVELOPMENT CAMPUS AW BE BU MI SH ALLOWABLE MATERIALS
LIBRARY USE LA TROBE UNIVERSITY SEMESTER ONE EXAMINATION PERIOD 2015 Student ID: Seat Number: Subject Code: CSE2WD Paper No: 1 Subject Name: WEB DEVELOPMENT Paper Name: Final examination Reading Time:
More informationHTML + CSS. ScottyLabs WDW. Overview HTML Tags CSS Properties Resources
HTML + CSS ScottyLabs WDW OVERVIEW What are HTML and CSS? How can I use them? WHAT ARE HTML AND CSS? HTML - HyperText Markup Language Specifies webpage content hierarchy Describes rough layout of content
More informationBy Ryan Stevenson. Guidebook #2 HTML
By Ryan Stevenson Guidebook #2 HTML Table of Contents 1. HTML Terminology & Links 2. HTML Image Tags 3. HTML Lists 4. Text Styling 5. Inline & Block Elements 6. HTML Tables 7. HTML Forms HTML Terminology
More informationHyper Text Markup Language
Hyper Text Markup Language HTML is a markup language. It tells your browser how to structure the webpage. HTML consists of a series of elements, which you use to enclose, or mark up different parts of
More informationIN Development in Platform Ecosystems Lecture 2: HTML, CSS, JavaScript
IN5320 - Development in Platform Ecosystems Lecture 2: HTML, CSS, JavaScript 27th of August 2018 Department of Informatics, University of Oslo Magnus Li - magl@ifi.uio.no 1 Today s lecture 1. 2. 3. 4.
More informationIntroducing the JavaScript DOM
Home : Articles : Introducing the JavaScript DOM Introducing the JavaScript DOM Tutorial by Matt Doyle Level: Beginner Published on 3 October 2008 Categories: Web Development > JavaScript > The Document
More informationthis is a cat CS50 Quiz 1 Review
CS50 Quiz 1 Review this is a cat CS50 Quiz 1 Review JavaScript CS50 Quiz 1 Review first, recall from zamyla Remember, PHP is run server-side. The HTML output of this PHP code is sent to the user. Server
More informationUNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?
UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? A 1: A text editor is a program that helps you write plain text (without any formatting) and save it to a file. A good example is
More informationJQuery WHY DIDN T WE LEARN THIS EARLIER??!
JQuery WHY DIDN T WE LEARN THIS EARLIER??! Next couple of weeks This week: Lecture: Security, jquery, Ajax Next Week: No lab (Easter) I may post a bonus (jquery) lab No quiz (yay!) Maybe a bonus one? Snuneymuxw
More informationIntroduction to Computer Science (I1100) Internet. Chapter 7
Internet Chapter 7 606 HTML 607 HTML Hypertext Markup Language (HTML) is a language for creating web pages. A web page is made up of two parts: the head and the body. The head is the first part of a web
More informationIntroduction to HTML
Introduction to HTML What is HTML? HTML is the standard markup language for creating Web pages. HTML stands for Hyper Text Markup Language HTML describes the structure of Web pages using markup HTML elements
More informationJavaScript and the DOM MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University
JavaScript and the DOM MIS 2402 Konstantin Bauman Department of MIS Fox School of Business Temple University Exam 2 Date: 11/06/18 four weeks from now! JavaScript, jquery 1 hour 20 minutes Use class workstations
More informationJQuery. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010
Lecture 23 JQuery Announcements HW#8 posted, due 12/3 HW#9 posted, due 12/10 HW#10 will be a survey due 12/14 Yariv will give Thursday lecture on privacy, security Yes, it will be on the exam! 1 Project
More informationImage Processing. HTML5 Canvas JavaScript Pixels
Image Processing HTML5 Canvas JavaScript Pixels Brent M. Dingle, Ph.D. 2015 Game Design and Development Program Mathematics, Statistics and Computer Science University of Wisconsin - Stout Provide Examples
More informationProper_Name Final Exam December 21, 2005 CS-081/Vickery Page 1 of 4
Proper_Name Final Exam December 21, 2005 CS-081/Vickery Page 1 of 4 NOTE: It is my policy to give a failing grade in the course to any student who either gives or receives aid on any exam or quiz. INSTRUCTIONS:
More informationTizen Web UI Technologies (Tizen Ver. 2.3)
Tizen Web UI Technologies (Tizen Ver. 2.3) Spring 2015 Soo Dong Kim, Ph.D. Professor, Department of Computer Science Software Engineering Laboratory Soongsil University Office 02-820-0909 Mobile 010-7392-2220
More informationTitle: Sep 12 10:58 AM (1 of 38)
Title: Sep 12 10:58 AM (1 of 38) Title: Sep 12 11:04 AM (2 of 38) Title: Sep 12 5:37 PM (3 of 38) Click here and then you can put in the resources. Title: Sep 12 5:38 PM (4 of 38) Title: Sep 12 5:42 PM
More informationWeb Programming/Scripting: JavaScript
CS 312 Internet Concepts Web Programming/Scripting: JavaScript Dr. Michele Weigle Department of Computer Science Old Dominion University mweigle@cs.odu.edu http://www.cs.odu.edu/~mweigle/cs312-f11/ 1 Outline!
More informationHTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript Objectives Explore the Document Object Model Add content using a script Trigger a script using an event handler Create
More informationMODULE 2 HTML 5 FUNDAMENTALS. HyperText. > Douglas Engelbart ( )
MODULE 2 HTML 5 FUNDAMENTALS HyperText > Douglas Engelbart (1925-2013) Tim Berners-Lee's proposal In March 1989, Tim Berners- Lee submitted a proposal for an information management system to his boss,
More informationDOM. Ajax Technology in Web Programming. Sergio Luján Mora. DLSI - Universidad de Alicante 1. API for accessing and manipulating HTML documents
Departamento de Lenguajes y Sistemas Informáticos Ajax Technology in Web Programming Sergio Luján Mora API for accessing and manipulating HTML documents DOM DLSI - Universidad de Alicante 1 Introduction
More informationMarkup Language. Made up of elements Elements create a document tree
Patrick Behr Markup Language HTML is a markup language HTML markup instructs browsers how to display the content Provides structure and meaning to the content Does not (should not) describe how
More informationINTRODUCTION TO WEB USING HTML What is HTML?
Geoinformation and Sectoral Statistics Section (GiSS) INTRODUCTION TO WEB USING HTML What is HTML? HTML is the standard markup language for creating Web pages. HTML stands for Hyper Text Markup Language
More informationDOM. Contents. Sergio Luján Mora. What is DOM? DOM Levels DOM Level 0 DOM Level 1. Departamento de Lenguajes y Sistemas Informáticos
DOM Sergio Luján Mora Departamento de Lenguajes y Sistemas Informáticos What is DOM? DOM Levels DOM Level 0 DOM Level 1 Contents 1 What is the DOM? The Document Object Model is an API for HTML and XML
More informationCSE 154 LECTURE 23: XML
CSE 154 LECTURE 23: XML Storing structured data in arbitrary text formats (bad) My note: BEGIN FROM: Alice Smith (alice@example.com) TO: Robert Jones (roberto@example.com) SUBJECT: Tomorrow's "Birthday
More informationLA TROBE UNIVERSITY SEMESTER ONE EXAMINATION PERIOD CAMPUS AW BE BU MI SH ALLOWABLE MATERIALS
LIBRARY USE LA TROBE UNIVERSITY SEMESTER ONE EXAMINATION PERIOD 2013 Student ID: Seat Number: Unit Code: CSE2WD Paper No: 1 Unit Name: Paper Name: Reading Time: Writing Time: Web Development Final 15 minutes
More informationLecture : 3. Practical : 2. Course Credit. Tutorial : 0. Total : 5. Course Learning Outcomes
Course Title Course Code WEB DESIGNING TECHNOLOGIES DCE311 Lecture : 3 Course Credit Practical : Tutorial : 0 Total : 5 Course Learning Outcomes At end of the course, students will be able to: Understand
More informationINTRODUCTION TO JAVASCRIPT
INTRODUCTION TO JAVASCRIPT Overview This course is designed to accommodate website designers who have some experience in building web pages. Lessons familiarize students with the ins and outs of basic
More informationJS Tutorial 3: InnerHTML Note: this part is in last week s tutorial as well, but will be included in this week s lab
JS Tutorial 3: InnerHTML Note: this part is in last week s tutorial as well, but will be included in this week s lab What if we want to change the text of a paragraph or header on a page? You can use:
More informationData Visualization (DSC 530/CIS )
Data Visualization (DSC 530/CIS 60201) CSS, SVG, and JavaScript Dr. David Koop Definition of Visualization Computerbased visualization systems provide visual representations of datasets designed to help
More information