CHAPTER 5 jQuery อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.

Slides:



Advertisements
Similar presentations
By ishaq shinwari.  jQuery is a lightweight, "write less, do more", JavaScript library.  The purpose of jQuery is to make it much easier to use JavaScript.
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,
CT-376 jQuery Most popular javascript library today Latest version:
SE-2840 Dr. Mark L. Hornick1 jQuery. jQuery is a library of JavaScript functions Helps minimize the amount of JavaScript you have to write in order to:
JQuery A Javascript Library Hard things made eas(ier) Norman White.
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
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.
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
School of Computing and Information Systems CS 371 Web Application Programming jQuery.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I JQuery Part II Jongwook.
Week 12: JQuery Write less, do more.. JQuery Basics Lightweight JavaScript Library – Emphasizes interaction between JavaScript and HTML – Reduces technical.
CS3L: Introduction to Symbolic Programming Summer 2008 Gilbert Chou Bonus Lecture: Web Programming.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I JQuery Part I Jongwook Woo,
CS428 Web Engineering Lecture 15 Introduction to Jquery.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
Anatomy of an App HTML, CSS, jQuery, jQuery Mobile CIS 136 Building Mobile Apps 1.
M. Taimoor Khan Courtesy: Norman White.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
Nguyen Ich Cuong.  Course duration: 45’  Purpose: Present Introduction to JQuery  Targeted attendees: NICorp Trainee  Tests/quiz: Yes - 10’
JQuery March 09 th,2009 Create by
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
Jquery Nasrullah. Jquery jQuery is a JavaScript Library. jQuery greatly simplifies JavaScript programming. jQuery is easy to learn.
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.
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
Introduction to jQuery. jQuery Quick facts Is a cross-compatible JavaScript library Released in 2006 by John Resig Simplifies HTML document traversing,
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Browser scripting jQuery Edited by: Trần Thị Mỹ Dung Ref:w3schools.com.
JavaScript Library. What is jQuery jQuery is a lightweight JavaScript library. The purpose is to make it easier to use JavaScript code on your website.
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.
Creating Dynamic Webpages
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
IS2802 Introduction to Multimedia Applications for Business Lecture 07: Introduction to jQuery Rob Gleasure
Web Programming JAvaScript Ajax Programming Web Programming /38.
CSS Hadas Kahsay. Overview  What is CSS  Basic syntax of CSS Rules  How to link CSS style to html documents  Browsers and CSS  Advantages of CSS.
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.
KAPITA SELEKTA INFORMATIKA Lasmedi Afuan, ST.M.Cs.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
JQuery Tutorial. What is jQuery jQuery is a JavaScript Library The purpose of jQuery is to make it much easier to use JavaScript on your website JavaScript.
HTML Introduction HTML Editors HTML Basic HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Formatting HTML Links HTML Head HTML CSS HTML.
Engr. Md. Nazim Uddin M.Sc. Eng. (CSE), B.Sc. Engg. (CSE), MIEB Cell: Website:
JQuery The Write Less, Do More, JavaScript Library.
JQuery is a fast, small, and feature-rich javascript library. It makes things like HTML document traversal and manipulation, event handling, animation,
What is jQuery?.
CS7026 jQuery Effects.
Introduction to Web programming
-By Yogita Nirmal.
Tek Raj Chhetri Code for Humans not for machine.
Intro to jQuery jQuery is a popular, and extensible, JavaScript library Supports … DOM manipulation CSS manipulation HTML event methods Effects & animations.
jQuery A Javascript Library Hard things made eas(ier)
Introduction to Web programming
JQuery Basics 소속 / 작성자 이 문서는 나눔글꼴로 작성되었습니다. 설치하기.
JQUERY Online TRAINING AT GOLOGICA
The Cliff Notes Version
HTML Level II (CyberAdvantage)
JavaScript & jQuery Timers, Effects, and Animations
JQuery with ASP.NET.
jQuery A Javascript Library Hard things made eas(ier)
JQuery Animation for beginners NOTES?!.
Web Programming Language
E-commerce Applications Development
Document Object Model.
Web Programming Language
SEEM4540 Tutorial 3 jQuery Wong Wai Chung.
Murach's JavaScript and jQuery (3rd Ed.)
JQuery.
Presentation transcript:

CHAPTER 5 jQuery อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1

Content jQuery Introduction jQuery Get Started jQuery Syntax jQuery Selectors jQuery Event Methods jQuery Effects - Hide and Show jQuery Effects - Fading jQuery Effects - Sliding jQuery Effects - Animation 2

Content jQuery Stop Animations jQuery Callback Functions jQuery - Chaining jQuery - Get Content and Attributes jQuery - Set Content and Attributes jQuery - Add Elements jQuery - Remove Elements jQuery - Get and Set CSS Classes jQuery - css() Method 3

jQuery Introduction What is jQuery? jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. The jQuery library contains the following features: HTML/DOM manipulation CSS manipulation HTML event methods Effects and animations AJAX Utilities 4

jQuery Get Started Adding jQuery to Your Web Pages There are several ways to start using jQuery on your web site. You can: Download the jQuery library from jQuery.com Include jQuery from a CDN, like Google 5 Downloading jQuery Download => jQuery.com The jQuery library is a single JavaScript file, and you reference it with the HTML

jQuery Syntax Basic syntax is: $(selector).action() A $ sign to define/access jQuery A (selector) to "query (or find)" HTML elements A jQuery action() to be performed on the element(s) Examples: $(this).hide() - hides the current element. $("p").hide() - hides all elements. $(".test").hide() - hides all elements with class="test". $("#test").hide() - hides the element with id="test". 6

jQuery Syntax (cont.) The Document Ready Event $(document).ready(function(){ // jQuery methods go here... }); 7

jQuery Selectors jQuery selectors allow you to select and manipulate HTML element(s). jQuery selectors are used to "find" (or select) HTML elements based on their id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.CSS Selectors 8

jQuery Selectors (cont.) The element Selector Example $(document).ready(function(){ $("button").click(function(){ $("p").hide();//use elements }); }); 9 The #id Selector Example $(document).ready(function(){ $("button").click(function(){ $("#test").hide(); //use id #test }); });

jQuery Selectors (cont.) The.class Selector Example $(document).ready(function(){ $("button").click(function(){ $(".test").hide();//use class.test }); }); 10 More Examples of jQuery Selectors SyntaxDescription $(“*")Selects all elements $(this)Selects the current HTML element $("p.intro")Selects all elements with class="intro" $("p:first")Selects the first element

jQuery Event Methods What are Events? 11 Mouse EventsKeyboard EventsForm EventsDocument/Window Events clickkeypresssubmitload dblclickkeydownchangeresize mouseenterkeyupfocusscroll mouseleave blurunload jQuery Syntax For Event Methods $("p").click(function(){ // action goes here!! });

jQuery Event Methods (cont.) Commonly Used jQuery Event Methods click() Example $("p").click(function(){ $(this).hide(); }); dblclick() Example $("p").dblclick(function(){ $(this).hide(); }); 12

jQuery Event Methods (cont.) Commonly Used jQuery Event Methods mouseenter() Example $("#p1").mouseenter(function(){ alert("You entered p1!"); }); mouseleave() Example $("#p1").mouseleave(function(){ alert("Bye! You now leave p1!"); }); 13

jQuery Event Methods (cont.) Commonly Used jQuery Event Methods mousedown() Example $("#p1").mousedown(function(){ alert("Mouse down over p1!"); }); mouseup() Example $("#p1").mouseup(function(){ alert("Mouse up over p1!"); }); 14

jQuery Event Methods (cont.) Commonly Used jQuery Event Methods hover() Example $("#p1").hover(function(){ alert("You entered p1!"); }, function(){ alert("Bye! You now leave p1!"); }); focus() Example $("input").focus(function(){ $(this).css("background-color", "#cccccc"); }); 15

jQuery Event Methods (cont.) Commonly Used jQuery Event Methods focus() And blue() $("input").focus(function(){ $(this).css("background-color", “red"); }); $("input").blur(function(){ $(this).css("background-color", “green"); }); 16

jQuery Effects - Hide and Show jQuery hide() and show() Syntax: $(selector).hide(speed,callback); Example $("#hide").click(function(){ $("p").hide(1000); }); $("#show").click(function(){ $("p").show(500); }); 17

jQuery Effects - Hide and Show (cont.) jQuery toggle() With jQuery, you can toggle between the hide() and show() methods with the toggle() method. Example $("button").click(function(){ $("p").toggle(); }); 18

jQuery Effects - Fading With jQuery you can fade elements in and out of visibility. jQuery Fading Methods fadeIn() fadeOut() fadeToggle() fadeTo() 19

jQuery Effects - Fading (cont.) jQuery fadeIn() And fadeOut() Method Syntax: $(selector).fadeIn(speed,callback); $(selector).fadeOut(speed,callback); Example $("button").click(function(){ $("#div1").fadeIn(); $("#div2").fadeIn("slow"); $("#div3").fadeIn(3000); }); 20

jQuery Effects - Fading (cont.) jQuery fadeToggle() Method Syntax: $(selector).fadeToggle(speed,callback); Example $("button").click(function(){ $("#div1").fadeToggle(); $("#div2").fadeToggle("slow"); $("#div3").fadeToggle(3000); }); 21

jQuery Effects - Fading (cont.) jQuery fadeTo() Method The jQuery fadeTo() method allows fading to a given opacity (value between 0 and 1). Syntax: $(selector).fadeTo(speed,opacity,callback); Example $("button").click(function(){ $("#div1").fadeTo("slow", 0.15); $("#div2").fadeTo("slow", 0.4); $("#div3").fadeTo("slow", 0.7); }); 22

jQuery Effects - Sliding jQuery Sliding Methods With jQuery you can create a sliding effect on elements. jQuery has the following slide methods: slideDown() slideUp() slideToggle() 23

jQuery Effects - Sliding (cont.) jQuery slideDown() And slideUp() Method Syntax: $(selector).slideDown(speed,callback); $(selector).slideUp(speed,callback); Example $("#flip").click(function(){ $("#panel").slideDown(); }); 24

jQuery Effects - Sliding (cont.) jQuery slideToggle() Method Syntax: $(selector).slideToggle(speed,callback); Example $("#flip").click(function(){ $("#panel").slideToggle(); }); 25

jQuery Effects - Animation jQuery Animations - The animate() Method Syntax: $(selector).animate({params},speed,callback); Example $("button").click(function(){ $("div").animate({left: '250px'}); }); *remember to first set the CSS position property of the element to relative, fixed, or absolute! 26

jQuery Effects - Animation (cont.) jQuery Animations - The animate() Method Syntax: $(selector).animate({params},speed,callback); Example $("button").click(function(){ $("div").animate({left: '250px'}); }); *remember to first set the CSS position property of the element to relative, fixed, or absolute! 27

jQuery Stop Animations jQuery stop() Method Syntax: $(selector).stop(stopAll,goToEnd); Example $(document).ready(function(){ $("#flip").click(function(){ $("#panel").slideDown(5000); }); $("#stop").click(function(){ $("#panel").stop(); }); 28 #panel, #flip { padding: 5px; font-size: 18px; text-align: center; background-color: #555; color: white; border: solid 1px #666; border-radius: 3px; } #panel { padding: 50px; display: none; }

jQuery Callback Functions syntax: $(selector).hide(speed,callback); Example with Callback $("button").click(function(){ $("p").hide("slow", function(){ alert("The paragraph is now hidden"); }); }); 29

jQuery - Chaining jQuery Callback Functions syntax: $(selector).hide(speed,callback); Example with Callback $("button").click(function(){ $("#p1").css("color", "red").slideUp(2000).slideDown(2000); }); 30

jQuery - Get Content and Attributes Get Content - text(), html(), and val() Example $("#btn1").click(function(){ alert("Text: " + $("#test").text()); }); $("#btn2").click(function(){ alert("HTML: " + $("#test").html()); }); $("#btn3").click(function(){ alert("Value: " + $("#test2").val()); }); 31

jQuery - Get Content and Attributes (cont.) Get Attributes - attr() Example $("button").click(function(){ alert($("#w3s").attr("href")); }); 32

jQuery - Set Content and Attributes Set Content - text(), html(), and val() Example $("#btn1").click(function(){ $("#test1").text("Hello world!"); }); $("#btn2").click(function(){ $("#test2").html(" Hello world! "); }); $("#btn3").click(function(){ $("#test3").val("Dolly Duck"); }); 33

jQuery - Set Content and Attributes (cont.) Set Attributes - attr() Example $("button").click(function(){ $("#w3s").attr("href"," "); }); 34

jQuery - Add Elements Add New HTML Content We will look at four jQuery methods that are used to add new content: append() - Inserts content at the end of the selected elements prepend() - Inserts content at the beginning of the selected elements after() - Inserts content after the selected elements before() - Inserts content before the selected elements 35

jQuery - Add Elements (cont.) jQuery append() Method Example $("p").append("Some appended text."); 36 jQuery prepend() Method Example $("p").prepend("Some prepended text."); jQuery after() and before() Methods Example $("img").after("Some text after"); $("img").before("Some text before");

jQuery - Remove Elements jQuery remove() Method Example $("#div1").remove(); 37 jQuery empty() Method Example $("#div1").empty(); Filter the Elements to be Removed Example $("p").remove(".test,.demo");

jQuery - Get and Set CSS Classes Example Stylesheet.blue { color: blue; } 38 jQuery addClass() Example $("button").click(function(){ $("h1, h2, p").addClass("blue"); }); jQuery romoveClass() Example $("button").click(function(){ $("h1, h2, p").removeClass("blue"); }); Or use toggleClass() $("h1, h2, p").toggleClass("blue");

jQuery - css() Method Return a CSS Property $("p").css("background-color"); 39 Set a CSS Property $("p").css("background-color", "yellow"); Set Multiple CSS Properties $("p").css({"background-color": "yellow", "font- size": "200%"});

40 THE END