<!DOCTYPE html>
<html>
<head>
<title>Week 8 - Intro to Frameworks</title>
</head>
<body>
<h1 id="headline">jQuery Practice</h1>
<ul id="list"></ul>
<script>
var colors = ["red","blue","yellow","black","green"];
</script>
</body>
</html>
function resetCalc(){
document.getElementById('bill').value = '';
var percBtns = document.getElementsByClassName('tip-btn');
for(var i=0; i < percBtns.length; i++){
percBtns[i].checked = false;
}
var tipBox = document.getElementById('tipamount');
tipBox.innerHTML = '$0.00';
}
What would you need to do to allow users to select only one radio button? Use Google!
...on jQuery
Even though we will mostly be working with it, I will introduce a couple other frameworks that operate similarly to jQuery. It's important that you remember that jQuery is not the only, and is not always the best, option for completing certain tasks.
Programming is about deciding what you want to do and then investigating the best option for getting it done.
To access the methods and shortcuts of any library or framework, you have to have access to them on your page
jQuery('selector').method(parameter);
or
jQuery('selector').method(function(){
//your function code here
});
To use jQuery, you have to declare when you are going to access the library. You can either write out jQuery before your selector or use the $ sign.
This method prevents your script from running until the page has loaded. It's best to wrap all your jQuery in this method to make sure all the elements you are targeting are on the page.
(In native JS this would be equivalent to window.onload)
$(document).ready(function(){
//your function code here
})
The Wrapper - The dollar sign calls the jQuery library and indicates that a jQuery method will be used on the element in the wrapper.
The Selector - the element that you are going to run your method on. This can be the page itself document or a tag 'h1', an ID '#idname' or class '.classname'
The Method - whatever jQuery method you are running on the element you've specified. In this case we are running ready, which means to wait until the page is loaded before running the code.
The beginning of your function. The parenthese after function is where you can pass in other information that your function needs, if anything. The code you are going to run goes inside the curly brackets.
You can run multiple methods on a single selector with jQuery. For example: $('h1').css('color','red').fadeOut(); will change the color of your headline and the fade it off the page.
In the Week 8 Dropbox, copy the file week8-definitions.docx and fill out the definitions for the terms and decribing the code. You'll need to use Google or the resources on the class website. Save your copy your folder in Week 8 in Dropbox.
You will be assigned a jQuery method, which you will research and demonstrate to the class how to use it.