SlideShare a Scribd company logo
1 of 30
Download to read offline
© 2020 Park22 Ventures LLC. All rights reserved.
Coding 101: Front End Web Development
Lesson 4: JQuery and Buttons
Uprise University
Learn something
© 2020 Park22 Ventures LLC. All rights reserved. 2
1. Intro to JQuery and Buttons
2. JQuery Selectors
3. JQuery Methods
Lesson Overview
© 2020 Park22 Ventures LLC. All rights reserved. 3
• 4.1. Color Switcher: User types color into form and presses submit button to change
background color of website
• 4.2. Background drop down menu: Create a pre-populated drop down menu that
changes the background picture when drop down menu is selected.
• 4.3. Grocery List: User can add or delete items from grocery list. App continues until
finish is entered in. Each iteration, user is shown entire grocery list. Grocery list is
displayed in HTML. User can enter items into a form and press add or delete buttons
to edit grocery list.
• 4.4. Bob’s blog: Allow users to click on a button to read more. Similar to blogs or
eCommerce more info buttons.
• 4.5. Traffic Light: Create a traffic light / stop light!
• 4.6 Cash Register: Add item dollar amounts to create a running tally of expenses.
• 4.7 Rock Paper Scissors: Play rock paper scissors against the computer.
• 4.8. User Profile: New users can create and edit a profile page. Data is stored
locally.
Project Overview
© 2020 Park22 Ventures LLC. All rights reserved. 4
• “Library” of JavaScript code to make it easier for you to use JS to interact and dynamcially change HTML
and CSS files
• Open-source, cross browser
• It allows you to easily perform DOM manipulation and event listening without some of the issues and
length of plain javascript
• Most websites use it
• Syntax format
• $(„CSSselector‟).action()
• Example syntax
• $(„button‟).click(color_switcher); /* When any button is clicked, color_switcher function is run */
1) Intro
What is JQuery? Why use JQuery?
© 2020 Park22 Ventures LLC. All rights reserved. 5
• Option 1) Add link to JQuery API in index.html file ABOVE the script link (it links to file with a CDN)
• <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
• /* Note if you don‟t add JQuery first then you won‟t be able to reference it in .js file */
• Option 2) Download JQuery file and link to it
• i) Save JQuery file locally as .js in a js folder
• ii) In your index.html file, add below code right before closing </body> tag
• <script src="js/myscript.js"></script>
• iii) Again, make sure this link comes before any of your JS file links
1) Intro
Adding JQuery to HTML
© 2020 Park22 Ventures LLC. All rights reserved. 6
• Wrap all of your JS and JQuery code with below method as good practice
• This prevents your code from running until the entire document is done loading
• $(document).ready(function() {
• // put all of your code in here
• });
1) Intro
Good practice
© 2020 Park22 Ventures LLC. All rights reserved. 7
2) JQuery Selectors
Selector Example Selector Description
* $(„*‟).click(color_switcher) // all elements
element $(„h2‟).click(color_switcher) // all <h2>‟s
#id $(„#big_box‟).click(color_switcher) // elements with id big_box
.class $(„.important‟).click(color_switcher) // elements with id big_box
selector1, selector2 $(„p, h1‟).click(color_switcher) // all <p>‟s and <h1>‟s
parent child $(„#sidebar a‟).click(color_switcher) // <a>‟s that are within sidebar id
parent > child $(„p > a‟).click(color_switcher) // <a>‟s that are direct children of <p>
Element.class $(„div.container‟).click(color_switcher) // all <div>‟s with class container
© 2020 Park22 Ventures LLC. All rights reserved. 8
3) JQuery Methods
Most commonly used (1 of 2)
Selector Example Method Description
.change() $('#check_boxes').change(prog1); // when check_boxes is changed (i.e.
checked / unchecked), then run prog1
.click() $('#id').click(edit_program); // when id is clicked, then
edit_program is run
.val() x = $(„#id‟).val(); // get value of element and set x to it;
can also set element values
.text() $(„#id‟).text("Changes h1 text to this”); // change html text
.css() $(„#id‟).css("background-color": "yellow"); // change CSS attribute
.attr() $(„#id‟).attr(„class‟,‟important‟); // add „important‟ class to id
.append() $(„#id‟).append(“<option> choice 4 </option>”);
$(„#id‟).append(`<option> ${my_var}</option>`);
// adds option html code to id
// adds option html code using variable
// CAUTION! This is a grave accent (`)
// Not a single quoatation („)
.remove() $(„#id‟).remove(); // deletes html element with id
.on() $('#id').on('click', '.btn-delete', delete_program); // similar to .click() method but used
after you use .append() to add html
© 2020 Park22 Ventures LLC. All rights reserved. 9
3) Methods
Additional methods (2 of 2)
Selector Example Method Description
.css() $(„#id‟).css({"color": "yellow", "font-size": “9px"}); // change multiple CSS attributes
.hide() $(„#id‟).hide(); // hides element
.show() $(„#id‟).show(); // shows element
.slideUp() $(„#id‟).slideUp(); // hides element by sliding it up
.slideDown() $(„#id‟).slideDown(); // shows element by sliding it down
.slideToggle() $(„#id‟).slideToggle(); // toggles between .slideUp() and
.slideDown() methods
.toggleClass() $(„#id‟).toggleClass(); // toggles between adding/removing one
or more class names
.attr() $(„#id‟).attr(“src”, “images/food”); // changes the source attribute picture to
a different picture
.children() $(„#id‟).children(); // returns all direct children of the
selected element
.parent() $(„#id‟).parent(); // returns the direct parent of the
selected element
.html() $(„#id‟).html(“<span> new text </span>”); // changes actual HTML vs. just text of
element
© 2020 Park22 Ventures LLC. All rights reserved. 10
• Create a form that allows the user to type in a color and the press a button to change the
background color of the webpage
• Hints:
• <input type="text">
• <button> </button>
• $('input').val();
• $('body').css("background-color",‟yellow‟);
• $('button').click(my_color_switcher_function);
Project 4.1. Color Switcher
Try it yourself before going to next slide
© 2020 Park22 Ventures LLC. All rights reserved. 11
Project 4.1. Color Switcher
Solution
© 2020 Park22 Ventures LLC. All rights reserved. 12
• Create a dynamic dropdown menu that allows a user to select what the background of the image will
be
• Find images of 6 different backgrounds that the user can choose from and store them in an images
folder
• Create 6 different classes, one for each background image
• Hints:
• $('form').change(set_picture_function);
• var background = $("#background_pick").val();
• $('body').attr('class',background);
• $('#pic').append('<option>' + picks[i] + '</option>');
Project 4.2. Background drop down menu
Try it yourself before going to next slide
© 2020 Park22 Ventures LLC. All rights reserved. 13
Project 4.2. Background drop down menu
Solution
© 2020 Park22 Ventures LLC. All rights reserved. 14
• Build a grocery shopping app that allows the user to add new items to a grocery list, have the list
displayed on the page, and allow the user to delete items that have been added
• When “add new item” button is clicked, the user should be prompted with an “enter item” prompt
• When the user presses ok, the app should add the item entered it an unordered html list and
concurrently add a button that allows the user to delete the item
• Hints
• $('#groceries').append("<li id='" + item_id + "'>" + new_item + "<button class='del_btn' value='"
+ item_id + "'> delete </button> </li>");
• var id = $(this).val();
• $(line).remove();
• $('#add_btn').click(add_item);
• $('#groceries').on('click', '.del_btn', delete_item);
Project 4.3. Grocery List
Try it yourself before going to next slide
© 2020 Park22 Ventures LLC. All rights reserved. 15
Project 4.3. Grocery List
Solution
© 2020 Park22 Ventures LLC. All rights reserved. 16
• Allow users to click on a button to read more. Similar to blogs or eCommerce more info buttons.
• Hints:
• $(„#id‟).show()
• $(„#id‟).hide()
• $(„#id‟).slideDown()
• $(„#id‟).click(run_my_cool_function)
Project 4.4. Bob’s Blog
Try it yourself before going to next slide
© 2020 Park22 Ventures LLC. All rights reserved. 17
Project 4.4. Bob’s Blog
Solution
© 2020 Park22 Ventures LLC. All rights reserved. 18
• Create a traffic light / stop light!
• Hints:
• $(„#id‟).css(„background-color‟,‟red‟);
• $(„#id‟).click(run_my_cool_function);
• Extra credit: make the light automatically switch from
red for 3 seconds to yellow for 1 second to green for 3
seconds and then back to red!
Project 4.5. Traffic Light
Try it yourself before going to next slide
© 2020 Park22 Ventures LLC. All rights reserved. 19
Project 4.5. Traffic Light
Solution
© 2020 Park22 Ventures LLC. All rights reserved. 20
• Add item dollar amounts to create a running tally of expenses.
• Hints:
• $(„#id‟).append(`<tr> ${my_var}</tr>`)
• $(„#id‟).val(„‟)
• $(„#id‟).submit(my_function)
• return
• my_num.toFixed(2)
• parseFloat()
• event.preventDefault()
Project 4.6. Cash Register
Try it yourself before going to next slide
CAUTION: This is a grave accent (`); It is not a
single parenthesis (‘)!!
© 2020 Park22 Ventures LLC. All rights reserved. 21
Project 4.6. Cash Register
Solution
© 2020 Park22 Ventures LLC. All rights reserved. 22
• Play rock paper scissors against the computer and keep score!
• Hints:
• $(„#id‟).removeClass(„rock‟)
• $(„#id‟).addClass(user_input)
• if ((x == y) && (a == b) { }
Project 4.7. Rock Paper Scissors
Try it yourself before going to next slide
© 2020 Park22 Ventures LLC. All rights reserved. 23
Project 4.7. Rock Paper Scissors
Solution
© 2020 Park22 Ventures LLC. All rights reserved. 24
• Create an app that allows a user to create a user
profile and submit it
• When user clicks submit button, it is saved to local
storage, and the user is taken to a profile page that
shows their profile
• Try to make the profile page look the one to the right
• Try to dynamically create the dropdown boxes and
the interests check boxes using JQuery
• Hints:
• <fieldset> <legend> <label> <textarea>
• localStorage.setItem("first_name",first_name);
• $('#cell').html(localStorage.getItem("cell"));
• window.location.href = "profile.html";
Project 4.8. User Profile
Try it yourself before going to next slide
© 2020 Park22 Ventures LLC. All rights reserved. 25
Project 4.8. User Profile
Solution (1 of 2)
© 2020 Park22 Ventures LLC. All rights reserved. 26
Project 4.8. User Profile
Solution (2 of 2)
© 2020 Park22 Ventures LLC. All rights reserved. 27
1. Intro to JQuery and Buttons
2. JQuery Selectors
3. JQuery Methods
Lesson Overview
© 2020 Park22 Ventures LLC. All rights reserved. 28
• 4.1. Color Switcher: User types color into form and presses submit button to change
background color of website
• 4.2. Background drop down menu: Create a pre-populated drop down menu that
changes the background picture when drop down menu is selected.
• 4.3. Grocery List: User can add or delete items from grocery list. App continues until
finish is entered in. Each iteration, user is shown entire grocery list. Grocery list is
displayed in HTML. User can enter items into a form and press add or delete buttons
to edit grocery list.
• 4.4. Bob’s blog: Allow users to click on a button to read more. Similar to blogs or
eCommerce more info buttons.
• 4.5. Traffic Light: Create a traffic light / stop light!
• 4.6 Cash Register: Add item dollar amounts to create a running tally of expenses.
• 4.7 Rock Paper Scissors: Play rock paper scissors against the computer.
• 4.8. User Profile: New users can create and edit a profile page. Data is stored
locally.
Project Overview
© 2020 Park22 Ventures LLC. All rights reserved. 29
• JQuery: “Library” of JavaScript code to make it easier for you to use JS to interact and dynamcially
change HTML and CSS files
• Library: Group of code files that share with you objects, functions, etc. so that you can easily use
commonly used functions in different programs; Many libraries are open-source (i.e. free to use).
• Open-source: Publicly available code to view and use; Editing is typically controlled to select users
• JQuery Selectors: Used to find and select HTML elements
• JQuery Methods: Functions built into JQuery that you can easily use
• JQuery Syntax format
• $(„CSSselector‟).action()
Vocab and Concept Review
© 2020 Park22 Ventures LLC. All rights reserved. 30
• Flashcard App: Build an application that allows user to learn and memorize a stack of five flash cards.
User should see “front” of card that has a prompt on it (e.g., what is the capital of the U.S.?). When the
user clicks a button, the card flips to the “back” and shows the answer (e.g., Washington D.C.). When
the user clicks the button again, it goes to the next card in the stack and shows the front of the card.
Once the stack is finished, the user goes back again to the first card.
Homework

More Related Content

Similar to 4 coding101 fewd_lesson4_j_query_and_buttons 20210105

Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)Damien Carbery
 
Giorgio Bignozzi - How to develop a Sticker plug-in for Magento 2: best practice
Giorgio Bignozzi - How to develop a Sticker plug-in for Magento 2: best practiceGiorgio Bignozzi - How to develop a Sticker plug-in for Magento 2: best practice
Giorgio Bignozzi - How to develop a Sticker plug-in for Magento 2: best practiceMeet Magento Italy
 
WordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesWordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesBrandon Dove
 
The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build Systemklipstein
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
Web Projects: From Theory To Practice
Web Projects: From Theory To PracticeWeb Projects: From Theory To Practice
Web Projects: From Theory To PracticeSergey Bolshchikov
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBen Limmer
 
Cordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web SkillsCordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web SkillsClay Ewing
 
Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Back End Developers - Denver Startup Week 2017Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Back End Developers - Denver Startup Week 2017Matt Raible
 
Week 8
Week 8Week 8
Week 8A VD
 
From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)Bramus Van Damme
 
Developing for LinkedIn's Application Platform
Developing for LinkedIn's Application PlatformDeveloping for LinkedIn's Application Platform
Developing for LinkedIn's Application PlatformTaylor Singletary
 
Lesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ayLesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ayCodecademy Ren
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponentsMartin Hochel
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)jeresig
 
JQuery in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in SeasideESUG
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyOrbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyMark Meeker
 
Single Page Applications in Angular (italiano)
Single Page Applications in Angular (italiano)Single Page Applications in Angular (italiano)
Single Page Applications in Angular (italiano)Fabio Biondi
 

Similar to 4 coding101 fewd_lesson4_j_query_and_buttons 20210105 (20)

Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
 
Giorgio Bignozzi - How to develop a Sticker plug-in for Magento 2: best practice
Giorgio Bignozzi - How to develop a Sticker plug-in for Magento 2: best practiceGiorgio Bignozzi - How to develop a Sticker plug-in for Magento 2: best practice
Giorgio Bignozzi - How to develop a Sticker plug-in for Magento 2: best practice
 
WordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesWordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin Pages
 
The Dojo Build System
The Dojo Build SystemThe Dojo Build System
The Dojo Build System
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Web Projects: From Theory To Practice
Web Projects: From Theory To PracticeWeb Projects: From Theory To Practice
Web Projects: From Theory To Practice
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profit
 
Cordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web SkillsCordova: Making Native Mobile Apps With Your Web Skills
Cordova: Making Native Mobile Apps With Your Web Skills
 
Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Back End Developers - Denver Startup Week 2017Front End Development for Back End Developers - Denver Startup Week 2017
Front End Development for Back End Developers - Denver Startup Week 2017
 
Week 8
Week 8Week 8
Week 8
 
From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)From Idea to App (or “How we roll at Small Town Heroes”)
From Idea to App (or “How we roll at Small Town Heroes”)
 
Developing for LinkedIn's Application Platform
Developing for LinkedIn's Application PlatformDeveloping for LinkedIn's Application Platform
Developing for LinkedIn's Application Platform
 
Lesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ayLesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ay
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)
 
JQuery in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in Seaside
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyOrbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case Study
 
Single Page Applications in Angular (italiano)
Single Page Applications in Angular (italiano)Single Page Applications in Angular (italiano)
Single Page Applications in Angular (italiano)
 
Going web native
Going web nativeGoing web native
Going web native
 

Recently uploaded

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Recently uploaded (20)

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

4 coding101 fewd_lesson4_j_query_and_buttons 20210105

  • 1. © 2020 Park22 Ventures LLC. All rights reserved. Coding 101: Front End Web Development Lesson 4: JQuery and Buttons Uprise University Learn something
  • 2. © 2020 Park22 Ventures LLC. All rights reserved. 2 1. Intro to JQuery and Buttons 2. JQuery Selectors 3. JQuery Methods Lesson Overview
  • 3. © 2020 Park22 Ventures LLC. All rights reserved. 3 • 4.1. Color Switcher: User types color into form and presses submit button to change background color of website • 4.2. Background drop down menu: Create a pre-populated drop down menu that changes the background picture when drop down menu is selected. • 4.3. Grocery List: User can add or delete items from grocery list. App continues until finish is entered in. Each iteration, user is shown entire grocery list. Grocery list is displayed in HTML. User can enter items into a form and press add or delete buttons to edit grocery list. • 4.4. Bob’s blog: Allow users to click on a button to read more. Similar to blogs or eCommerce more info buttons. • 4.5. Traffic Light: Create a traffic light / stop light! • 4.6 Cash Register: Add item dollar amounts to create a running tally of expenses. • 4.7 Rock Paper Scissors: Play rock paper scissors against the computer. • 4.8. User Profile: New users can create and edit a profile page. Data is stored locally. Project Overview
  • 4. © 2020 Park22 Ventures LLC. All rights reserved. 4 • “Library” of JavaScript code to make it easier for you to use JS to interact and dynamcially change HTML and CSS files • Open-source, cross browser • It allows you to easily perform DOM manipulation and event listening without some of the issues and length of plain javascript • Most websites use it • Syntax format • $(„CSSselector‟).action() • Example syntax • $(„button‟).click(color_switcher); /* When any button is clicked, color_switcher function is run */ 1) Intro What is JQuery? Why use JQuery?
  • 5. © 2020 Park22 Ventures LLC. All rights reserved. 5 • Option 1) Add link to JQuery API in index.html file ABOVE the script link (it links to file with a CDN) • <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> • /* Note if you don‟t add JQuery first then you won‟t be able to reference it in .js file */ • Option 2) Download JQuery file and link to it • i) Save JQuery file locally as .js in a js folder • ii) In your index.html file, add below code right before closing </body> tag • <script src="js/myscript.js"></script> • iii) Again, make sure this link comes before any of your JS file links 1) Intro Adding JQuery to HTML
  • 6. © 2020 Park22 Ventures LLC. All rights reserved. 6 • Wrap all of your JS and JQuery code with below method as good practice • This prevents your code from running until the entire document is done loading • $(document).ready(function() { • // put all of your code in here • }); 1) Intro Good practice
  • 7. © 2020 Park22 Ventures LLC. All rights reserved. 7 2) JQuery Selectors Selector Example Selector Description * $(„*‟).click(color_switcher) // all elements element $(„h2‟).click(color_switcher) // all <h2>‟s #id $(„#big_box‟).click(color_switcher) // elements with id big_box .class $(„.important‟).click(color_switcher) // elements with id big_box selector1, selector2 $(„p, h1‟).click(color_switcher) // all <p>‟s and <h1>‟s parent child $(„#sidebar a‟).click(color_switcher) // <a>‟s that are within sidebar id parent > child $(„p > a‟).click(color_switcher) // <a>‟s that are direct children of <p> Element.class $(„div.container‟).click(color_switcher) // all <div>‟s with class container
  • 8. © 2020 Park22 Ventures LLC. All rights reserved. 8 3) JQuery Methods Most commonly used (1 of 2) Selector Example Method Description .change() $('#check_boxes').change(prog1); // when check_boxes is changed (i.e. checked / unchecked), then run prog1 .click() $('#id').click(edit_program); // when id is clicked, then edit_program is run .val() x = $(„#id‟).val(); // get value of element and set x to it; can also set element values .text() $(„#id‟).text("Changes h1 text to this”); // change html text .css() $(„#id‟).css("background-color": "yellow"); // change CSS attribute .attr() $(„#id‟).attr(„class‟,‟important‟); // add „important‟ class to id .append() $(„#id‟).append(“<option> choice 4 </option>”); $(„#id‟).append(`<option> ${my_var}</option>`); // adds option html code to id // adds option html code using variable // CAUTION! This is a grave accent (`) // Not a single quoatation („) .remove() $(„#id‟).remove(); // deletes html element with id .on() $('#id').on('click', '.btn-delete', delete_program); // similar to .click() method but used after you use .append() to add html
  • 9. © 2020 Park22 Ventures LLC. All rights reserved. 9 3) Methods Additional methods (2 of 2) Selector Example Method Description .css() $(„#id‟).css({"color": "yellow", "font-size": “9px"}); // change multiple CSS attributes .hide() $(„#id‟).hide(); // hides element .show() $(„#id‟).show(); // shows element .slideUp() $(„#id‟).slideUp(); // hides element by sliding it up .slideDown() $(„#id‟).slideDown(); // shows element by sliding it down .slideToggle() $(„#id‟).slideToggle(); // toggles between .slideUp() and .slideDown() methods .toggleClass() $(„#id‟).toggleClass(); // toggles between adding/removing one or more class names .attr() $(„#id‟).attr(“src”, “images/food”); // changes the source attribute picture to a different picture .children() $(„#id‟).children(); // returns all direct children of the selected element .parent() $(„#id‟).parent(); // returns the direct parent of the selected element .html() $(„#id‟).html(“<span> new text </span>”); // changes actual HTML vs. just text of element
  • 10. © 2020 Park22 Ventures LLC. All rights reserved. 10 • Create a form that allows the user to type in a color and the press a button to change the background color of the webpage • Hints: • <input type="text"> • <button> </button> • $('input').val(); • $('body').css("background-color",‟yellow‟); • $('button').click(my_color_switcher_function); Project 4.1. Color Switcher Try it yourself before going to next slide
  • 11. © 2020 Park22 Ventures LLC. All rights reserved. 11 Project 4.1. Color Switcher Solution
  • 12. © 2020 Park22 Ventures LLC. All rights reserved. 12 • Create a dynamic dropdown menu that allows a user to select what the background of the image will be • Find images of 6 different backgrounds that the user can choose from and store them in an images folder • Create 6 different classes, one for each background image • Hints: • $('form').change(set_picture_function); • var background = $("#background_pick").val(); • $('body').attr('class',background); • $('#pic').append('<option>' + picks[i] + '</option>'); Project 4.2. Background drop down menu Try it yourself before going to next slide
  • 13. © 2020 Park22 Ventures LLC. All rights reserved. 13 Project 4.2. Background drop down menu Solution
  • 14. © 2020 Park22 Ventures LLC. All rights reserved. 14 • Build a grocery shopping app that allows the user to add new items to a grocery list, have the list displayed on the page, and allow the user to delete items that have been added • When “add new item” button is clicked, the user should be prompted with an “enter item” prompt • When the user presses ok, the app should add the item entered it an unordered html list and concurrently add a button that allows the user to delete the item • Hints • $('#groceries').append("<li id='" + item_id + "'>" + new_item + "<button class='del_btn' value='" + item_id + "'> delete </button> </li>"); • var id = $(this).val(); • $(line).remove(); • $('#add_btn').click(add_item); • $('#groceries').on('click', '.del_btn', delete_item); Project 4.3. Grocery List Try it yourself before going to next slide
  • 15. © 2020 Park22 Ventures LLC. All rights reserved. 15 Project 4.3. Grocery List Solution
  • 16. © 2020 Park22 Ventures LLC. All rights reserved. 16 • Allow users to click on a button to read more. Similar to blogs or eCommerce more info buttons. • Hints: • $(„#id‟).show() • $(„#id‟).hide() • $(„#id‟).slideDown() • $(„#id‟).click(run_my_cool_function) Project 4.4. Bob’s Blog Try it yourself before going to next slide
  • 17. © 2020 Park22 Ventures LLC. All rights reserved. 17 Project 4.4. Bob’s Blog Solution
  • 18. © 2020 Park22 Ventures LLC. All rights reserved. 18 • Create a traffic light / stop light! • Hints: • $(„#id‟).css(„background-color‟,‟red‟); • $(„#id‟).click(run_my_cool_function); • Extra credit: make the light automatically switch from red for 3 seconds to yellow for 1 second to green for 3 seconds and then back to red! Project 4.5. Traffic Light Try it yourself before going to next slide
  • 19. © 2020 Park22 Ventures LLC. All rights reserved. 19 Project 4.5. Traffic Light Solution
  • 20. © 2020 Park22 Ventures LLC. All rights reserved. 20 • Add item dollar amounts to create a running tally of expenses. • Hints: • $(„#id‟).append(`<tr> ${my_var}</tr>`) • $(„#id‟).val(„‟) • $(„#id‟).submit(my_function) • return • my_num.toFixed(2) • parseFloat() • event.preventDefault() Project 4.6. Cash Register Try it yourself before going to next slide CAUTION: This is a grave accent (`); It is not a single parenthesis (‘)!!
  • 21. © 2020 Park22 Ventures LLC. All rights reserved. 21 Project 4.6. Cash Register Solution
  • 22. © 2020 Park22 Ventures LLC. All rights reserved. 22 • Play rock paper scissors against the computer and keep score! • Hints: • $(„#id‟).removeClass(„rock‟) • $(„#id‟).addClass(user_input) • if ((x == y) && (a == b) { } Project 4.7. Rock Paper Scissors Try it yourself before going to next slide
  • 23. © 2020 Park22 Ventures LLC. All rights reserved. 23 Project 4.7. Rock Paper Scissors Solution
  • 24. © 2020 Park22 Ventures LLC. All rights reserved. 24 • Create an app that allows a user to create a user profile and submit it • When user clicks submit button, it is saved to local storage, and the user is taken to a profile page that shows their profile • Try to make the profile page look the one to the right • Try to dynamically create the dropdown boxes and the interests check boxes using JQuery • Hints: • <fieldset> <legend> <label> <textarea> • localStorage.setItem("first_name",first_name); • $('#cell').html(localStorage.getItem("cell")); • window.location.href = "profile.html"; Project 4.8. User Profile Try it yourself before going to next slide
  • 25. © 2020 Park22 Ventures LLC. All rights reserved. 25 Project 4.8. User Profile Solution (1 of 2)
  • 26. © 2020 Park22 Ventures LLC. All rights reserved. 26 Project 4.8. User Profile Solution (2 of 2)
  • 27. © 2020 Park22 Ventures LLC. All rights reserved. 27 1. Intro to JQuery and Buttons 2. JQuery Selectors 3. JQuery Methods Lesson Overview
  • 28. © 2020 Park22 Ventures LLC. All rights reserved. 28 • 4.1. Color Switcher: User types color into form and presses submit button to change background color of website • 4.2. Background drop down menu: Create a pre-populated drop down menu that changes the background picture when drop down menu is selected. • 4.3. Grocery List: User can add or delete items from grocery list. App continues until finish is entered in. Each iteration, user is shown entire grocery list. Grocery list is displayed in HTML. User can enter items into a form and press add or delete buttons to edit grocery list. • 4.4. Bob’s blog: Allow users to click on a button to read more. Similar to blogs or eCommerce more info buttons. • 4.5. Traffic Light: Create a traffic light / stop light! • 4.6 Cash Register: Add item dollar amounts to create a running tally of expenses. • 4.7 Rock Paper Scissors: Play rock paper scissors against the computer. • 4.8. User Profile: New users can create and edit a profile page. Data is stored locally. Project Overview
  • 29. © 2020 Park22 Ventures LLC. All rights reserved. 29 • JQuery: “Library” of JavaScript code to make it easier for you to use JS to interact and dynamcially change HTML and CSS files • Library: Group of code files that share with you objects, functions, etc. so that you can easily use commonly used functions in different programs; Many libraries are open-source (i.e. free to use). • Open-source: Publicly available code to view and use; Editing is typically controlled to select users • JQuery Selectors: Used to find and select HTML elements • JQuery Methods: Functions built into JQuery that you can easily use • JQuery Syntax format • $(„CSSselector‟).action() Vocab and Concept Review
  • 30. © 2020 Park22 Ventures LLC. All rights reserved. 30 • Flashcard App: Build an application that allows user to learn and memorize a stack of five flash cards. User should see “front” of card that has a prompt on it (e.g., what is the capital of the U.S.?). When the user clicks a button, the card flips to the “back” and shows the answer (e.g., Washington D.C.). When the user clicks the button again, it goes to the next card in the stack and shows the front of the card. Once the stack is finished, the user goes back again to the first card. Homework