10/30/2014 - 9:04 PM

Jquery Basics

Jquery Basics

 Show slow 
 Add click event with anonymous to removable 


$(".order_form").hide().before("<a href='#' class='order_now'>Order Now</a>");
			var $link = $(this);
			return false;
//Form Validation

var $submit = $(".submit input");
			var $required = $(".required");
			function containsBlanks(){
				var blanks = ${ return $(this).val() == "";});
				return $.inArray(true, blanks) != -1;

			function isValidEmail(email){
				return email.indexOf("@") != -1;

			function requiredFilledIn(){
				if(containsBlanks() || !isValidEmail($("#email").val())) 

			$("#form span").hide();
				//Check all required fields.

				//Check for a valid email.




/* Create a method called 'requiredValues' that returns an array of all the values 
   of inputs with the class of 'required'.*/

var requiredValues = function()
     var myArray = new Array();
     return myArray;


/* Create a method called 'containsBlanks' that returns true if any inputs with class 
 'required' has an empty string in, false if not. 
The steps are:

Create function containsBlanks
Create an array in the function
Cycle over ".required"
Push if the input is empty on to the array
Return if the array has any trues in (the video suggests one method)

structure the code
function containsBlanks(){
//Create an array 'values'
//Cycle through each the '.required' input
//In the each push the comparison of $(this).val() == "" where "" is an empty string
//return if the 'values' array has a true value in it


function containsBlanks(){
  var valuesArray = new Array();
    valuesArray.push($(this).val() == "");
  return valuesArray.sort().pop();


//Call 'map' on the inputs with the class 'required' and return each of their values and store it in a variable named 'values'.
var values = $(".required").map(function(){ return $(this).val(); })

//check for Andrew string

$.inArray("Andrew", values);

// Using Jquery to select an element
//jquery let you add behavior to an element by selecting the css selector 
//To select a selector you use 

$("nav a")

//Manipulate or add behavior - add the method we want to call
//If you want to hide a page element you use the hide method


//some method takes argument ex the before method 
//it takes a string of html and add it before the selected element
//hello before the element


// other methods take functions as argument to be wrote when a event happen like a click
// this is know as handler 


//you can write a handler using an anonimous function - replace handler word
       /** Code **/}).hide();
 //hide message and then show slow