SlideShare una empresa de Scribd logo
1 de 27
Getting
Started with
jQuery
Prepared by: Laila Shandy M. Buncab
BS Computer Engineering
Treston International College
What is jQuery?
• A lightweight, “write less, do more” JavaScript library.
• Designed to make it easier to use JavaScript on your
website.
• It takes a lot common tasks that require many lines of
JavaScript code to accomplish, and wraps them into
method that you can call in a single line of code.
What is jQuery?
• Simplifies a lot of complicated tasks from JavaScript, like
AJAX calls and DOM manipulation.
• Contains the following features:
– HTML/DOM manipulation
– CSS manipulation
– HTML event methods
– Effects and animations
– AJAX
– Utilities
jQuery Installation
• Download jQuery library from http://jquery.com
• Include jQuery from a CDN, like Google
• There are two versions of jQuery available for
downloading:
1. Production version - this is for your live website
because it has been minified and compressed
2. Development version - this is for testing and
development (uncompressed and readable code)
Both versions can be downloaded
from jQuery.com.
jQuery Installation
• The jQuery library is a single JavaScript file, and you
reference it with the HTML <script> tag (notice that the
<script> tag should be inside the <head> section):
jQuery Installation
• If you don't want to download and host jQuery yourself,
you can include it from a CDN (Content Delivery
Network).
• Both Google and Microsoft host jQuery.
• To use jQuery from Google or Microsoft, use one of the
following:
jQuery Installation
Google CDN:
Microsoft CDN:
jQuery Syntax
• The jQuery syntax is tailor made for selecting HTML elements and
performing some action on the element(s).
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 <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".
jQuery Syntax
• The first thing you need to be up and running with
jQuery is what’s called the “document ready” handler.
Pretty much everything you code in jQuery will be
contained inside one of these. This accomplishes two
things: First, it ensures that the code does not run until
the DOM is ready. This confirms that any elements being
accessed are actually in existence, so the script won’t
return any errors. Second, this ensures that your code is
unobtrusive. That is, it’s separated from content (XHTML)
and presentation (CSS).
jQuery Syntax
jQuery Selectors
• Most important parts of the jQuery library because it
allows you to manipulate and select HTML element(s).
• $("div"); // selects all HTML div elements
• $("#myElement"); // selects one HTML element with ID
"myElement"
• $(".myClass"); // selects HTML elements with class
"myClass"
• $("p#myElement"); // selects HTML paragraph element
with ID "myElement"
• $("ul li a.navigation");// selects anchors with class
"navigation" that are nested in list items
jQuery Selectors
• jQuery supports the use of all CSS selectors, even
those in CSS3. Here are some examples of alternate
selectors:
• $("p > a"); // selects anchors that are direct children of
paragraphs
• $("input[type=text]"); // selects inputs that have
specified type
• $("a:first"); // selects the first anchor on the page
• $("p:odd"); // selects all odd numbered paragraphs
• $("li:first-child"); // selects each list item that's the first
child in its list
jQuery Selectors
• jQuery also allows the use of its own custom selectors. Here
are some examples:
• $(":animated"); // selects elements currently being animated
• $(":button"); // selects any button elements (inputs or buttons)
• $(":radio"); // selects radio buttons
• $(":checkbox"); // selects checkboxes
• $(":checked"); // selects checkboxes or radio buttons that are
selected
• $(":header"); // selects header elements (h1, h2, h3, etc.)
Manipulating and Accessing CSS Class Names
jQuery allows
• jQuery allows you to easily add, remove, and toggle
CSS classes, which comes in handy for a variety of
practical uses. Here are the different syntaxes for
accomplishing this:
• $("div").addClass("content"); // adds class "content" to
all <div> elements
• $("div").removeClass("content"); // removes class
"content" from all <div> elements
• $("div").toggleClass("content");
• // toggles the class "content" on all <div> elements
(adds it if it doesn't exist, //and removes it if it does)
Manipulating and Accessing CSS Class Names
jQuery allows
• You can also check to see if a selected element has
a particular CSS class, and then run some code if it
does. You would check this using an if statement.
Here is an example:
if ($("#myElement").hasClass("content")) {
// do something here
• }
• You could also check a set of elements (instead of
just one), and the result would return "true" if any
one of the elements contained the class.
Manipulating CSS Styles with
jQuery
• CSS styles can be added to elements easily using
jQuery, and it's done in a cross-browser fashion. Here are
some examples to demonstrate this:
• $("p").css("width", "400px"); // adds a width to all
paragraphs
• $("#myElement").css("color", "blue") // makes text color
blue on element #myElement
• $("ul").css("border", "solid 1px #ccc") // adds a border to
all lists
Adding, Removing, and Appending
Elements and Content
• There are a number of ways to manipulate groups of
elements with jQuery, including manipulating the
content of those elements (whether text, inline elements,
etc).
1. Get the HTML of any element (similar to innerHTML in
JavaScript):
Adding, Removing, and Appending
Elements and Content
2. If you don't want to access the HTML, but only want the
text of an element:
3. Using similar syntax to the past two examples, you can
change the HTML or text content of a specified element:
Adding, Removing, and Appending
Elements and Content
4. To append content to an element:
Dealing with Events in jQuery
• Specific event handlers can be established using the following
code:
The code inside function() will only run when an anchor is
clicked. Some other common events you might use in jQuery
include:
blur, focus, hover, keydown, load, mousemove, resize, scroll, sub
mit, select.
Showing and Hiding Elements with
jQuery
• The syntax for showing, hiding an element (or toggling
show/hide) is:
Showing and Hiding Elements with
jQuery
• Remember that the "toggle" command will change whatever state the element
currently has, and the parameters are both optional. The first parameter indicates the
speed of the showing/hiding. If no speed is set, it will occur instantly, with no
animation. A number for "speed" represents the speed in milliseconds. The second
parameter is an optional function that will run when the command is finished
executing.
• You can also specifically choose to fade an element in or out, which is always done by
animation:
Showing and Hiding Elements with
jQuery
• To fade an element only partially, either in or out:
• The second parameter (0.4) represents "opacity", and is similar to the
way opacity is set in CSS. Whatever the opacity is to start with, it will
animate (fadeTo) until it reaches the setting specified, at the speed
set (2000 milliseconds). The optional function (called a "callback
function") will run when the opacity change is complete. This is the
way virtually all callback functions in jQuery work.
jQuery Animations and Effects
• You can slide elements, animate elements, and even stop
animations in mid-sequence. To slide elements up or
down:
jQuery Animations and Effects
• To animate an element, you do so by telling jQuery the
CSS styles that the item should change to. jQuery will set
the new styles, but instead of setting them instantly (as
CSS or raw JavaScript would do), it does so gradually,
animating the effect at the chosen speed:
References
• http://www.w3schools.com
• http://www.impressivewebs.com
• http://www.jqfundamentals.com
END 

Más contenido relacionado

La actualidad más candente

jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryGunjan Kumar
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introductionTomi Juhola
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuerykolkatageeks
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryAlek Davis
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery EssentialsMark Rackley
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Libraryrsnarayanan
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQueryAlan Hecht
 
Web Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONSWeb Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONSRSolutions
 

La actualidad más candente (20)

jQuery
jQueryjQuery
jQuery
 
Learn css3
Learn css3Learn css3
Learn css3
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery Effects
jQuery EffectsjQuery Effects
jQuery Effects
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
J query module1
J query module1J query module1
J query module1
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
J query lecture 1
J query lecture 1J query lecture 1
J query lecture 1
 
Structure on a freeform world
Structure on a freeform worldStructure on a freeform world
Structure on a freeform world
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 
Web Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONSWeb Development Course - JQuery by RSOLUTIONS
Web Development Course - JQuery by RSOLUTIONS
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Jquery library
Jquery libraryJquery library
Jquery library
 

Destacado

Multiphase system
Multiphase systemMultiphase system
Multiphase systemYouhong Yao
 
Mz Develpment Process Web Doug
Mz Develpment Process Web DougMz Develpment Process Web Doug
Mz Develpment Process Web Dougwilhemjorgensen
 
Contemporary developments in_corrosion_inhibitors__review_of_patents
Contemporary developments in_corrosion_inhibitors__review_of_patentsContemporary developments in_corrosion_inhibitors__review_of_patents
Contemporary developments in_corrosion_inhibitors__review_of_patentsJairo Giraldo
 
Diseño de estrategia de comunicación
Diseño de estrategia de comunicaciónDiseño de estrategia de comunicación
Diseño de estrategia de comunicaciónIluicatl Apellidos
 
Actividad con-los-dispositivos-medicos
Actividad con-los-dispositivos-medicosActividad con-los-dispositivos-medicos
Actividad con-los-dispositivos-medicosJiimena Diiaz
 
Industrial applications of bentonite
Industrial applications of bentoniteIndustrial applications of bentonite
Industrial applications of bentoniteMohamed Aboud
 

Destacado (8)

6 semana impacto ambiental - tabla
6 semana impacto ambiental - tabla6 semana impacto ambiental - tabla
6 semana impacto ambiental - tabla
 
Multiphase system
Multiphase systemMultiphase system
Multiphase system
 
Mz Develpment Process Web Doug
Mz Develpment Process Web DougMz Develpment Process Web Doug
Mz Develpment Process Web Doug
 
Contemporary developments in_corrosion_inhibitors__review_of_patents
Contemporary developments in_corrosion_inhibitors__review_of_patentsContemporary developments in_corrosion_inhibitors__review_of_patents
Contemporary developments in_corrosion_inhibitors__review_of_patents
 
Diseño de estrategia de comunicación
Diseño de estrategia de comunicaciónDiseño de estrategia de comunicación
Diseño de estrategia de comunicación
 
Sufrage
SufrageSufrage
Sufrage
 
Actividad con-los-dispositivos-medicos
Actividad con-los-dispositivos-medicosActividad con-los-dispositivos-medicos
Actividad con-los-dispositivos-medicos
 
Industrial applications of bentonite
Industrial applications of bentoniteIndustrial applications of bentonite
Industrial applications of bentonite
 

Similar a Getting Started with jQuery

Similar a Getting Started with jQuery (20)

Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
J query presentation
J query presentationJ query presentation
J query presentation
 
J query presentation
J query presentationJ query presentation
J query presentation
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
J query
J queryJ query
J query
 
Web technologies-course 11.pptx
Web technologies-course 11.pptxWeb technologies-course 11.pptx
Web technologies-course 11.pptx
 
Javascript libraries
Javascript librariesJavascript libraries
Javascript libraries
 
Jquery
JqueryJquery
Jquery
 
JQuery
JQueryJQuery
JQuery
 
JQuery
JQueryJQuery
JQuery
 
J query
J queryJ query
J query
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
Introduction to jquery mobile with Phonegap
Introduction to jquery mobile with PhonegapIntroduction to jquery mobile with Phonegap
Introduction to jquery mobile with Phonegap
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdfUnit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
Unit 1 - What is jQuery_Why jQuery_Syntax_Selectors.pdf
 
JQuery
JQueryJQuery
JQuery
 
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
 

Último

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Último (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Getting Started with jQuery

  • 1. Getting Started with jQuery Prepared by: Laila Shandy M. Buncab BS Computer Engineering Treston International College
  • 2. What is jQuery? • A lightweight, “write less, do more” JavaScript library. • Designed to make it easier to use JavaScript on your website. • It takes a lot common tasks that require many lines of JavaScript code to accomplish, and wraps them into method that you can call in a single line of code.
  • 3. What is jQuery? • Simplifies a lot of complicated tasks from JavaScript, like AJAX calls and DOM manipulation. • Contains the following features: – HTML/DOM manipulation – CSS manipulation – HTML event methods – Effects and animations – AJAX – Utilities
  • 4. jQuery Installation • Download jQuery library from http://jquery.com • Include jQuery from a CDN, like Google • There are two versions of jQuery available for downloading: 1. Production version - this is for your live website because it has been minified and compressed 2. Development version - this is for testing and development (uncompressed and readable code) Both versions can be downloaded from jQuery.com.
  • 5. jQuery Installation • The jQuery library is a single JavaScript file, and you reference it with the HTML <script> tag (notice that the <script> tag should be inside the <head> section):
  • 6. jQuery Installation • If you don't want to download and host jQuery yourself, you can include it from a CDN (Content Delivery Network). • Both Google and Microsoft host jQuery. • To use jQuery from Google or Microsoft, use one of the following:
  • 8. jQuery Syntax • The jQuery syntax is tailor made for selecting HTML elements and performing some action on the element(s). 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 <p> elements. $(".test").hide() - hides all elements with class="test". $("#test").hide() - hides the element with id="test".
  • 9. jQuery Syntax • The first thing you need to be up and running with jQuery is what’s called the “document ready” handler. Pretty much everything you code in jQuery will be contained inside one of these. This accomplishes two things: First, it ensures that the code does not run until the DOM is ready. This confirms that any elements being accessed are actually in existence, so the script won’t return any errors. Second, this ensures that your code is unobtrusive. That is, it’s separated from content (XHTML) and presentation (CSS).
  • 11. jQuery Selectors • Most important parts of the jQuery library because it allows you to manipulate and select HTML element(s). • $("div"); // selects all HTML div elements • $("#myElement"); // selects one HTML element with ID "myElement" • $(".myClass"); // selects HTML elements with class "myClass" • $("p#myElement"); // selects HTML paragraph element with ID "myElement" • $("ul li a.navigation");// selects anchors with class "navigation" that are nested in list items
  • 12. jQuery Selectors • jQuery supports the use of all CSS selectors, even those in CSS3. Here are some examples of alternate selectors: • $("p > a"); // selects anchors that are direct children of paragraphs • $("input[type=text]"); // selects inputs that have specified type • $("a:first"); // selects the first anchor on the page • $("p:odd"); // selects all odd numbered paragraphs • $("li:first-child"); // selects each list item that's the first child in its list
  • 13. jQuery Selectors • jQuery also allows the use of its own custom selectors. Here are some examples: • $(":animated"); // selects elements currently being animated • $(":button"); // selects any button elements (inputs or buttons) • $(":radio"); // selects radio buttons • $(":checkbox"); // selects checkboxes • $(":checked"); // selects checkboxes or radio buttons that are selected • $(":header"); // selects header elements (h1, h2, h3, etc.)
  • 14. Manipulating and Accessing CSS Class Names jQuery allows • jQuery allows you to easily add, remove, and toggle CSS classes, which comes in handy for a variety of practical uses. Here are the different syntaxes for accomplishing this: • $("div").addClass("content"); // adds class "content" to all <div> elements • $("div").removeClass("content"); // removes class "content" from all <div> elements • $("div").toggleClass("content"); • // toggles the class "content" on all <div> elements (adds it if it doesn't exist, //and removes it if it does)
  • 15. Manipulating and Accessing CSS Class Names jQuery allows • You can also check to see if a selected element has a particular CSS class, and then run some code if it does. You would check this using an if statement. Here is an example: if ($("#myElement").hasClass("content")) { // do something here • } • You could also check a set of elements (instead of just one), and the result would return "true" if any one of the elements contained the class.
  • 16. Manipulating CSS Styles with jQuery • CSS styles can be added to elements easily using jQuery, and it's done in a cross-browser fashion. Here are some examples to demonstrate this: • $("p").css("width", "400px"); // adds a width to all paragraphs • $("#myElement").css("color", "blue") // makes text color blue on element #myElement • $("ul").css("border", "solid 1px #ccc") // adds a border to all lists
  • 17. Adding, Removing, and Appending Elements and Content • There are a number of ways to manipulate groups of elements with jQuery, including manipulating the content of those elements (whether text, inline elements, etc). 1. Get the HTML of any element (similar to innerHTML in JavaScript):
  • 18. Adding, Removing, and Appending Elements and Content 2. If you don't want to access the HTML, but only want the text of an element: 3. Using similar syntax to the past two examples, you can change the HTML or text content of a specified element:
  • 19. Adding, Removing, and Appending Elements and Content 4. To append content to an element:
  • 20. Dealing with Events in jQuery • Specific event handlers can be established using the following code: The code inside function() will only run when an anchor is clicked. Some other common events you might use in jQuery include: blur, focus, hover, keydown, load, mousemove, resize, scroll, sub mit, select.
  • 21. Showing and Hiding Elements with jQuery • The syntax for showing, hiding an element (or toggling show/hide) is:
  • 22. Showing and Hiding Elements with jQuery • Remember that the "toggle" command will change whatever state the element currently has, and the parameters are both optional. The first parameter indicates the speed of the showing/hiding. If no speed is set, it will occur instantly, with no animation. A number for "speed" represents the speed in milliseconds. The second parameter is an optional function that will run when the command is finished executing. • You can also specifically choose to fade an element in or out, which is always done by animation:
  • 23. Showing and Hiding Elements with jQuery • To fade an element only partially, either in or out: • The second parameter (0.4) represents "opacity", and is similar to the way opacity is set in CSS. Whatever the opacity is to start with, it will animate (fadeTo) until it reaches the setting specified, at the speed set (2000 milliseconds). The optional function (called a "callback function") will run when the opacity change is complete. This is the way virtually all callback functions in jQuery work.
  • 24. jQuery Animations and Effects • You can slide elements, animate elements, and even stop animations in mid-sequence. To slide elements up or down:
  • 25. jQuery Animations and Effects • To animate an element, you do so by telling jQuery the CSS styles that the item should change to. jQuery will set the new styles, but instead of setting them instantly (as CSS or raw JavaScript would do), it does so gradually, animating the effect at the chosen speed: