Chengyu Sun California State University, Los Angeles

Slides:



Advertisements
Similar presentations
Getting Started with jQuery. 1. Introduction to jQuery 2. Selection and DOM manipulation Contents 2.
Advertisements

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,
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
JQuery CS 380: Web Programming. What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling,
JQuery A Javascript Library Hard things made eas(ier) Norman White.
Document Object Model (DOM) JavaScript manipulation of the DOM.
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.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
4.1 JavaScript Introduction
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
A really fairly simple guide to: mobile browser-based application development (part 4, JQuery & DOM) Chris Greenhalgh G54UBI / Chris Greenhalgh.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
DOM and JavaScript Aryo Pinandito.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
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.
JQUERY | INTRODUCTION. jQuery  Open source JavaScript library  Simplifies the interactions between  HTML document, or the Document Object Model (DOM),
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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.
JavaScript IV ECT 270 Robin Burke. Outline DOM JS document model review W3C DOM.
JavaScript - A Web Script Language Fred Durao
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
LOGO sparcs.org 1 jQuery Tutorial Presenter ㅎㅇㅎㅇ.
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.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
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.
Modifying HTML attributes and CSS values. Learning Objectives By the end of this lecture, you should be able to: – Select based on a class (as opposed.
School of Computing and Information Systems CS 371 Web Application Programming JavaScript - DOM Modifying the Page from within.
Understanding JavaScript and Coding Essentials Lesson 8.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
JavaScript Object Model. Biggest Advantage of JavaScript  I can access values of HTML elements using JavaScript  I can modify values of HTML elements.
Introduction to JQuery COGS 187A – Fall JQuery jQuery is a JavaScript library, and allows us to manipulate HTML and CSS after the page has been.
Introduction to JavaScript LIS390W1A Web Technologies and Techniques 24 Oct M. Cameron Jones.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Introduction to Web Site Development Department of Computer Science California State University, Los Angeles Lecture 9: JavaScript.
Introduction to JavaScript DOM Instructor: Sergey Goldman.
CS520 Web Programming Introduction to Ajax and jQuery Chengyu Sun California State University, Los Angeles.
THE DOM.
JQuery.
Introduction to.
Unit M Programming Web Pages with
CS5220 Advanced Topics in Web Programming JavaScript and jQuery
CS 371 Web Application Programming
Intro to JavaScript CS 1150 Spring 2017.
CGS 3066: Web Programming and Design Spring 2017
Introduction to Web programming
JavaScript Functions.
CS3220 Web and Internet Programming Client-Side JavaScript and jQuery
JavaScript Using JavaScript.
Document Object Model (DOM): Objects and Collections
JavaScript Introduction
DHTML Javascript Internet Technology.
JQuery with ASP.NET.
DHTML Javascript Internet Technology.
Working with Dynamic Content and Styles
..
Javascript and JQuery SRM DSC.
E-commerce Applications Development
JavaScript and Events CS Programming Languages for Web Applications
Creating dynamic/interactive web pages
JavaScript and Events CS Programming Languages for Web Applications
Presentation transcript:

Chengyu Sun California State University, Los Angeles CS5220 Advanced Topics in Web Programming Client-Side JavaScript and jQuery Chengyu Sun California State University, Los Angeles

Client-Side JavaScript Example: j1.html Embed JavaScript in HTML using <script> Tag Link to external file or enclose code directly Can appear any number of times in both <head> and <body> HTML 5 no longer requires the type attribute Run inside a browser

Processing an HTML Document <html> <head><title>JavaScript Example</title></head> <body> <h1>JavaScript Example</h1> <p>Some content.</p> </body> </html> As a text file – very difficult As an object

Document Object Model (DOM) Representing documents as objects so they can be processed more easily by a programming language

DOM Representation document <html> <head> <body> <title> <h1> <p> “JavaScript Example” “JavaScript Example” “Some content.”

Manipulate a Document Find Elements Modify Elements Create Elements

Find Elements document.getElementById() document.getElementsByName() document.getElementsByTagName()

Modify Elements ... HTMLElement properites and methods IE innerHTML innerText insertAdjacentHTML() insertAdjacentText() Netscape/Mozilla Element-specific

... Modify Elements node setAttribute(), removeAttribute() appendChild(), removeChild() insertBefore(), replaceChild()

Create Elements document createElement() createTextNode()

Example: Document Manipulation with JavaScript Example: j2.1.html Problems with plain client-side JavaScript Verbose code for even simple tasks Browser compatibility

jQuery: Make Client-Side JavaScript Great Again Hide browser incompatibility Greatly simplify/improve DOM operations, event handling, and asynchronous request and response Usage statistics - https://trends.builtwith.com/javascript/javascript-library

Using jQuery Example: j2.2.html Usage jQuery wrapper Selectors Elements Events and event handling DOM manipulation

jQuery Wrapper jQuery() or $() Return a collection of matched elements either found in the DOM based on passed argument(s) or created by passing an HTML string. $( "input[name='firstName']" ) $( "#who" ) $( "#t1" ) Selector

Basic Selectors By id By tag name By CSS class By attribute $(“#foo”) $(“div”) By CSS class $(“.foo”) By attribute $(“[name]”) $(“[name=‘joe’]”)

Combine Selectors Select all the <div> elements with CSS class foo and an attribute bar $(“div.foo[bar]”) Select all the <div> elements, and all the elements with CSS class foo, and all the elements with an attribute bar $(“div,.foo,[bar]”)

What Can We Do With An Element Get and set html() attr() prop() val() Manipulate CSS addClass() removeClass() toggleClass() hasClass() Property tagName <input name=“username” value=“cysun” /> Attribute name val()

Typical Event and Event Handling in jQuery Event Handler $("#click").click( function(){ ... ... }); Unobtrusive JavaScript: separate style, behavior, and structure. <button id="click“ onclick="display();"> Click Me</button>

Document Ready Event Triggered when the DOM hierarchy of the HTML document is fully constructed $( document ).ready( handler ) $().ready( handler ) (not recommended) $( handler )

Other Events Mouse events Keyboard events Form events Browser events .click() .dbclick() … Keyboard events .keyup() .keydown() .keypress() Form events .change() .submit() … Browser events .resize() Document events

DOM Manipulation Insertion Removal Replacement Around (i.e. parent) Inside (i.e. children) Outside (i.e. sibling) Removal Replacement Example: $("#t1").append("<tr><td>John</td><td>Doe</td></tr>");

Example: jQuery Basics j3.html What program languages do you know? + - -