Matthew Batchelder. Agenda  JavaScript: What it is and isn't  JavaScript: Uses  What is the DOM?  What is AJAX?  jQuery FTW! Manipulating page elements.

Slides:



Advertisements
Similar presentations
The jQuery library. What is jQuery ? A javascript lightweight library Is very easy to use Is powerful Is cross-browser compatible Downloadable from jQuery.com,
Advertisements

JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
The Web Warrior Guide to Web Design Technologies
19-Jun-15 Ajax. The hype Ajax (sometimes capitalized as AJAX) stands for Asynchronous JavaScript And XML Ajax is a technique for creating “better, faster,
20-Jun-15 JavaScript and HTML Simple Event Handling.
Ajax Dr Jim Briggs WEBP Ajax1. 2 Ajax Asynchronous JavaScript And XML Method of creating more interactive web applications Moves more of the application.
JavaScript Client Side scripting. Client-side Scripts Client-side scripts, which run on the user’s workstation can be used to: Validate user inputs entered.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
Definition from Wikipedia.  The Prototype JavaScript Framework  implemented as a single file of JavaScript code  named prototype.js (
JQuery CS 268. What is jQuery? From their web site:
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Internet Applications Spring Review Last week –MySQL –Questions?
JavaScript and The Document Object Model MMIS 656 Web Design Technologies Acknowledgements: 1.Notes from David Shrader, NSU GSCIS 2.Some material adapted.
Jquery IS JQuery Jquery Example of mouseover event that shows a submenu when menu selected: $(‘#menu’).mouseover(function() { $(‘#submenu’).show();
Chapter 6 JavaScript and AJAX. Objectives Explain the purpose and history of JavaScript Describe JavaScript features Explain the event-driven nature of.
JQuery March 09 th,2009 Create by
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
JS: Document Object Model (DOM)
Selectors. Learning Objectives By the end of this lecture, you should be able to: – Select items using jQuery based on ID, class name, or HTML tag. –
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
DOM and JavaScript Aryo Pinandito.
D2L Notes Be sure to submit your link in the dropbox provided on D2L You can just upload an empty text file if a file upload is required Do not use D2L.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
5.2 DOM (Document Object Model). 2 Motto: To write it, it took three months; to conceive it three minutes; to collect the data in it — all my life. —F.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Animation & Effects Using JQuery. What is jQuery? jQuery is a lightweight, JavaScript library. The purpose of jQuery is to make it much easier to use.
JQuery Youn-Hee Han
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Web Development 101 Presented by John Valance
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Web Programming Language Week 9 Dr. Ken Cosh Introducing jQuery.
Rich Internet Applications 3. Client JavaScript. Document Object Model (DOM) The DOM, is an interface that allows scripts or programs to access and manipulate.
School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within.
Host Objects: Browsers and the DOM
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
CHAPTER 7 JQUERY WHAT IS JQUERY? jQuery is a script. It is written in JavaScript.
JQUERY AND AJAX
DOM Dr. Reda Salama. Back to the HTML DOM Once we get a response back from the server, we probably want to update our HTML page The HTML page itself is.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
Introduction to.
JavaScript and HTML Simple Event Handling 11-May-18.
Programming Web Pages with JavaScript
CS 371 Web Application Programming
Introduction to JavaScript Events
HTML.
14 A Brief Look at JavaScript and jQuery.
JavaScript and HTML Simple Event Handling 19-Sep-18.
CSE 154 Lecture 11: More Events.
Events.
Introduction to jQuery
Javascript and JQuery SRM DSC.
JavaScript and Events CS Programming Languages for Web Applications
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and Events CS Programming Languages for Web Applications
JavaScript and HTML Simple Event Handling 4-Oct-19.
Presentation transcript:

Matthew Batchelder

Agenda  JavaScript: What it is and isn't  JavaScript: Uses  What is the DOM?  What is AJAX?  jQuery FTW! Manipulating page elements (the DOM) in sweet ways Simplified AJAX Other Coolness Pluggability  jQuery in myPlymouth

Before We Start!  Important tools to have Use Firefox ○ Firebug ○ JS Debugging FTW ○ Web Developer Toolbar (handy) A sexy text editor (not notepad)

JS: What it is and isn’t  NOT Java despite its name  ECMAScript  More than form validation  Client-Side Scripting Language Dynamic Weakly Typed Object-Oriented (Prototype-Based)  DOM Event Tool

JavaScript Sandbox  Scripts run in a “sandbox” Can only perform web-related actions, not File-System actions Constrained by a “Same Origin Policy”

JS: Usage  Drop this puppy in your page: Example JS Page // javascript code goes here …

JS: Literals  Values (the stuff on the right of the equal sign) are literals. var myNumber = 123; var myString = ‘Bork!’; var myBoolean = true; var myFunction = function(){ return ‘hello’;} var myRegExp = /bork/gi; var myArray = [1, 2, 3]; var myCarObject = { color: ‘red’, tires: 4, windows: 6 }

JS: Objects  Everything in JS is an Object All literals are object literals.  Those literals can be written: var myNumber = new Number(123); var myString = new String(‘Bork!’); var myBoolean = new Boolean(true); var myFunction = new Function(‘’, “return ‘hello’”);} var myRegExp = new RegExp(‘bork’); var myArray = new Array(); myArray[0] = 1; myArray[1] = 2; myArray[2] = 3; var myCarObject = new Object(); myCarObject.color = ‘red’; myCarObject.tires = 4; myCarObject.windows = 6;

JS: Objects  Objects values are accessed using dot (“.”) notation:  example example Examples var bork = 'Bork!'; var w00t = { hello: 'Greetings', yo: function(){ alert(bork + ' ' + this.hello); } }; var zomg = { nested: { iMeanReallyNested: { seriously: { out: function(){ alert('whee!'); } }; w00t.yo(); zomg.nested.iMeanReallyNested.seriously.out();...

JS: Control Structures if(bork) { //... } else { //... } while(bork) { //... } for(var i = 0; i< 10; i++) { //... } for(var element in array_of_elements) { //... } do { //... } while(bork); switch(bork) { case 1: // if bork == 1... case 'whee': // if bork == 'whee'... case false: // if bork == false... default: // otherwise... } try { //... } catch(err) { //... }

What is the DOM?  DOM == Document Object Model  The DOM is hierarchical Example JS Page

Finding DOM Elements  document.getElementById() returns a specific element  document.getElementByTag() returns an array of elements

DOM Element Attributes  nodeName  nodeValue  nodeType  parentNode  childNodes  firstChild  lastChild  previousSibling  nextSibling  attributes  ownerDocument  1 = an HTML element  2 = an element attribute  3 = text  8 = an HTML comment  9 = a document  10 = a document type definition DOM AttributesNode Types Here’s a good article that uses these.good article

Manipulating the DOM  Dynamically creating and adding elements document.createElement appendChild  example example

innerHTML  Why go through the trouble of creating Nodes?  More efficient  Easier  example example

Events  Click  Dblclick  Mousedown  Mouseup  Mouseover  Mousemove  Mouseout  Keypress  Keydown  Keyup  Select  Change  Submit  Reset  Focus  Blur  Load  Unload  Abort  Error  Resize  Scroll Mouse Keyboard Frame/ObjectForm

Simple Alert Box Example Message Box Page alert(‘I like butter’); …

Confirm Box Bound to an Event Example Message Box Page function doLoad() { document.getElementById('sweet-link').addEventListener(‘click’, confirmClick, false); }//end doLoad function confirmClick() { return confirm(‘Are you sure you wish to go to that link?’); }//end confirmClick window.addEventListener(‘load’, doLoad, false); BorkWeb example

Hiding/Displaying Elements  Element visibility is a nice use of events and DOM manipulation  example example

AJAX  AJAX (Asychronous Javascript and XML)  Gives you the ability to load content dynamically! Loading content on demand Possible usability Issues Possible performance problems and benefits  Limitation: No AJAX calls beyond the sandbox. Note: The way around this is with XSS (Cross Site Scripting)…which can be dangerous if done poorly.XSS

Ajax: XMLHttpRequest  Loading content on demand: function ajax(url, vars, callbackFunction){ var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0"); request.open("GET", url, true); request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); request.onreadystatechange = function(){ if (request.readyState == 4 && request.status == 200){ if (request.responseText){ callbackFunction(request.responseText); } }; request.send(vars); }//end ajax function out(text){ document.getElementById('content').innerHTML = text; }//end out function ajaxCall(){ ajax(' false; }//end ajaxCall function doLoad(){ document.getElementById('sweet-link').addEventListener('click', ajaxCall, false); }//doLoad window.addEventListener('load', doLoad, false);  exampleexample

Things can actually be a bit easier. How much? Well most of the above.

jQuery. That’s what we use on campus. It is awesome.

What is jQuery?  jQuery is a sweet JavaScript Library Its Mantra: Find stuff and do stuff with it Focuses on simplicity  Get it herehere  Check out the docsdocs

Finding Elements  Say goodbye to document.getElementById() and document.getElementByTag()  Say hello to: $() Uses CSS Selectors to find elements and returns them as an array of elements.CSS Selectors

Finding Elements With $ $(‘a’) $(‘.class’) $(‘#id’) $(‘.content div’) $(‘input[name=bork]’) $(‘input:first’) Here’s an example.example Check out the selector syntax for more info.

Lets do some of the stuff we already did…  Adding Text Fields Adding Text Fields  Toggling Element Visibility Toggling Element Visibility  Ajax Content Ajax Content

jQuery Coolness  Browser data $.browser  Effects Sliding Fading Animating  Chaining $(‘a’).click(function(){alert(‘hello’); return false;}).css(‘font-weight’,’bold’).fadeOut(‘slow’);

jQuery Plugins  Pluggable! Additional jQuery functionality added by including jQuery plugins.jQuery plugins

jQuery in myPlymouth  Go Sidebar  Bookmarks  Tab Stack  Etc…  Check out the source.source

Resources: Slide Examples, jQuery, Image Sprites, Mega Man!Slide ExamplesjQueryImage Sprites Mega Man