SlideShare a Scribd company logo
Mehrab Hossain
Cell: 01933616015
www.easyforall.org
Why Study JavaScript?
• JavaScript is one of the 3 languages all web developers must learn:
• 1. HTML to define the content of web pages
• 2. CSS to specify the layout of web pages
• 3. JavaScript to program the behavior of web pages
JavaScript Display Possibilities
• JavaScript can "display" data in different ways:
• Writing into an HTML element, using innerHTML.
• Writing into the HTML output using document.write().
• Writing into an alert box, using window.alert().
• Writing into the browser console, using console.log().
JavaScript Keywords
• Break
• Continue
• Debugger
• Do..while
• For
• function
• If ….else
• Return
• Switch
• Try…..catch
• var
JavaScript Values
• The JavaScript syntax defines two types of values: Fixed values and
variable values.
• Fixed values are called literals.
• Example: 10.50, “Johan Doe”
• Variable values are called variables.
• Example: var x = 6;
JavaScript Comments
• JavaScript comments can be used to explain JavaScript code, and to
make it more readable.
• Single Line Comments
• Single line comments start with //.
• Multi-line Comments
• Multi-line comments start with /* and end with */.
JavaScript Variables
• JavaScript variables are containers for storing data values.
• Example:
• var x = 5;
var y = 6;
JavaScript Type Operators
Operator Description
typeof Returns the type of a variable
instanceof Returns true if an object is an instance of an object
type
Data Types
• String
• Number
• Boolean
• Undefined
• Null
• Array
• Object
JavaScript Functions
• A JavaScript function is a block of code designed to perform a
particular task.
• Example:
• function myFunction(p1, p2) {
return p1 * p2;
}
JavaScript Objects
• You have already learned that JavaScript variables are containers for
data values.
• Objects are variables too. But objects can contain many values.
• var car = {type:"Fiat", model:"500", color:"white"};
JavaScript Function Scope
• In JavaScript there are two types of scope:
• Local scope
• Global scope
JavaScript Events
• An HTML event can be something the browser does, or something a
user does.
• Here are some examples of HTML events:
• An HTML web page has finished loading
• An HTML input field was changed
• An HTML button was clicked
• <element event='some JavaScript'>
JavaScript Math Object
• Math.round()
• Math.pow()
• Math.sqrt()
• Math.abs()
• Math.ceil()
• Math.floor()
• Math.sin()
• Math.cos()
• Math.min() and Math.max()
• Math.random()
JavaScript Arrays
• JavaScript arrays are used to store multiple values in a single variable.
• Example:
• var cars = ["Saab", "Volvo", "BMW"];
Popping and Pushing
• The pop() method removes the last element from an array:
• var fruits = ["Banana", "Orange", "Apple", "Mango"];
• fruits.pop();
• The push() method adds a new element to an array (at the end):
• var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
JavaScript Errors - Throw and Try to Catch
• The try statement lets you test a block of code for errors.
• The catch statement lets you handle the error.
• The throw statement lets you create custom errors.
• The finally statement lets you execute code, after try and catch,
regardless of the result.
JavaScript Best Practices
• Avoid global variables,
• avoid new,
• avoid ==,
• avoid eval()
JavaScript Versions
Year Name Description
1997 ECMAScript 1 First Edition.
1998 ECMAScript 2 Editorial changes only.
1999 ECMAScript 3 Added Regular Expressions.
Added try/catch.
ECMAScript 4 Was never released.
2009 ECMAScript 5 Added "strict mode".
Added JSON support.
2011 ECMAScript 5.1 Editorial changes.
2015 ECMAScript 6 Added classes and modules.
2016 ECMAScript 7 Added exponential operator (**).
Added Array.prototype.includes.
JavaScript JSON(JavaScript Object Notation)
• JSON is a format for storing and transporting data.
JavaScript Form Validation
• HTML form validation can be done by JavaScript.
• Server side validation is performed by a web server, after input has
been sent to the server.
• Client side validation is performed by a web browser, before input is
sent to a web server.
JavaScript Object Properties
• The syntax for accessing the property
of an object is:
• objectName.property // person.age
• or
• objectName["property"] // person["age"]
• Show data form Object:
• for (variable in object) {
code to be executed
}
Accessing Object Methods
• JavaScript methods are the actions that can be performed on objects.
• Example:
• var person = {
• firstName: "John",
• fullName : function() {
• return this.firstName;
• }
• };
• You access an object method with the following syntax:
• objectName.methodName()
JavaScript Object Constructors
• function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
var myFather = new Person("John", "Doe", 50, "blue");
var myMother = new Person("Sally", "Rally", 48, "green");
JavaScript Object Prototypes
• Every JavaScript object has a prototype. The prototype is also an
object.
• All JavaScript objects inherit their properties and methods from their
prototype.
JS Functions
• Function Definitions
• Function Parameters
• Function Invocation
• Function Call
• Function Apply
JavaScript HTML DOM Document
Method Description
document.getElementById(id) Find an element by element id
document.getElementsByTagName(name) Find elements by tag name
document.getElementsByClassName(name) Find elements by class name
Finding HTML Elements
Changing HTML Elements
Method Description
element.innerHTML = new html content Change the inner HTML of an element
element.attribute = new value Change the attribute value of an HTML element
element.setAttribute(attribute, value) Change the attribute value of an HTML element
element.style.property = new style Change the style of an HTML element
Adding and Deleting Elements
Method Description
document.createElement(element) Create an HTML element
document.removeChild(element) Remove an HTML element
document.appendChild(element) Add an HTML element
document.replaceChild(element) Replace an HTML element
document.write(text) Write into the HTML output stream
Changing HTML Style
• To change the style of an HTML element, use this syntax:
• document.getElementById(id).style.property = new style
HTML DOM Events
• HTML DOM events allow JavaScript to register different event
handlers on elements in an HTML document.
• References:
• https://www.w3schools.com/jsref/dom_obj_event.asp
The addEventListener() method
• The addEventListener() method attaches an event handler to the
specified element.
• Syntax:
• element.addEventListener(event, function, useCapture);
JavaScript Window
• Two properties can be used to determine the size of the browser window.
• Both properties return the sizes in pixels:
• window.innerHeight - the inner height of the browser window (in pixels)
• window.innerWidth - the inner width of the browser window (in pixels)
• Some other methods:
• window.open() - open a new window
• window.close() - close the current window
• window.moveTo() -move the current window
• window.resizeTo() -resize the current window
Window Screen
• The window.screen object can be written without the window prefix.
• screen.width
• screen.height
• screen.availWidth
• screen.availHeight
• screen.colorDepth
• screen.pixelDepth
JavaScript Window Location
• Window location can redirect any page
• Example:
• document.getElementById("demo").innerHTML =
"Page path is " + window.location.pathname;
JavaScript Timing Events
• The two key methods to use with JavaScript are:
• setTimeout(function, milliseconds)
Executes a function, after waiting a specified number of milliseconds.
• setInterval(function, milliseconds)
Same as setTimeout(), but repeats the execution of the function
continuously.
What is AJAX?
• AJAX = Asynchronous JavaScript And XML.
• AJAX is not a programming language.
• AJAX just uses a combination of:
 A browser built-in XMLHttpRequest object (to request data from a web server)
 JavaScript and HTML DOM (to display or use the data)
AJAX - The XMLHttpRequest Object
• All modern browsers support the XMLHttpRequest object.
• Systax:
• variable = new XMLHttpRequest();
AJAX - Send a Request To a Server
• The XMLHttpRequest object is used to exchange data with a server.
• xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
Method Description
open(method, url, async) Specifies the type of request
method: the type of request: GET or POST
url: the server (file) location
async: true (asynchronous) or false (synchronous)
send() Sends the request to the server (used for GET)
send(string) Sends the request to the server (used for POST)
GET or POST?
• GET is simpler and faster than POST, and can be used in most cases.
• However, always use POST requests when:
 A cached file is not an option (update a file or database on the server).
 Sending a large amount of data to the server (POST has no size limitations).
 Sending user input (which can contain unknown characters), POST is more robust and
secure than GET.
AJAX - Server Response
Property Description
onreadystatechange Defines a function to be called when the readyState property changes
readyState Holds the status of the XMLHttpRequest.
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
status 200: "OK"
403: "Forbidden"
404: "Page not found"
For a complete list go to the Http Messages Reference
statusText Returns the status-text (e.g. "OK" or "Not Found")
jQuery
• jQuery is a JavaScript Library.
• jQuery greatly simplifies JavaScript programming.
• jQuery is easy to learn.
jQuery Selectors
• jQuery selectors are one of the most important parts of the jQuery
library.
• Example:
• Element Name/Tag Name
• Id
• Class
jQuery Effects - Hide and Show
• Example:
• $(selector).hide(speed,callback);
$(selector).show(speed,callback);
jQuery Effects - Fading
• With jQuery you can fade elements in and out of visibility.
• $(selector).fadeIn(speed,callback);
• $(selector).fadeOut(speed,callback);
• $(selector).fadeToggle(speed,callback);
• $(selector).fadeTo(speed,opacity,callback);
jQuery Effects - Sliding
• jQuery has the following slide methods:
• slideDown()
• slideUp()
• slideToggle()
jQuery - Get Content and Attributes
• Three simple, but useful, jQuery methods for DOM manipulation are:
text() - Sets or returns the text content of selected elements
html() - Sets or returns the content of selected elements (including
HTML markup)
val() - Sets or returns the value of form fields
jQuery - Remove Elements
• To remove elements and content, there are mainly two jQuery
methods:
• remove() - Removes the selected element (and its child elements)
• empty() - Removes the child elements from the selected element
jQuery - Get and Set CSS Classes
• jQuery has several methods for CSS manipulation. We will look at the
following methods:
• addClass() - Adds one or more classes to the selected elements
• removeClass() - Removes one or more classes from the selected elements
• toggleClass() - Toggles between adding/removing classes from the selected
elements
• css() - Sets or returns the style attribute
Thank You

More Related Content

What's hot

Simplify AJAX using jQuery
Simplify AJAX using jQuerySimplify AJAX using jQuery
Simplify AJAX using jQuerySiva Arunachalam
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
Terry Yoast
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
Collaboration Technologies
 
Ajax chap 2.-part 1
Ajax chap 2.-part 1Ajax chap 2.-part 1
Ajax chap 2.-part 1
Mukesh Tekwani
 
Ajax chap 3
Ajax chap 3Ajax chap 3
Ajax chap 3
Mukesh Tekwani
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects
WebStackAcademy
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
prince Loffar
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
Terry Yoast
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
Javascript
JavascriptJavascript
Javascript
Prashant Kumar
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - Introduction
WebStackAcademy
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
Terry Yoast
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Azure F#unctions
Azure F#unctionsAzure F#unctions
Azure F#unctions
☁️ Mikhail Shilkov
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
Terry Yoast
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
Terry Yoast
 

What's hot (20)

Simplify AJAX using jQuery
Simplify AJAX using jQuerySimplify AJAX using jQuery
Simplify AJAX using jQuery
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
27javascript
27javascript27javascript
27javascript
 
Ajax chap 2.-part 1
Ajax chap 2.-part 1Ajax chap 2.-part 1
Ajax chap 2.-part 1
 
Ajax chap 3
Ajax chap 3Ajax chap 3
Ajax chap 3
 
Ajax
AjaxAjax
Ajax
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
 
Javascript
JavascriptJavascript
Javascript
 
jQuery - Chapter 1 - Introduction
 jQuery - Chapter 1 - Introduction jQuery - Chapter 1 - Introduction
jQuery - Chapter 1 - Introduction
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Azure F#unctions
Azure F#unctionsAzure F#unctions
Azure F#unctions
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
 
Linq
LinqLinq
Linq
 

Similar to javaScript and jQuery

PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Java script
Java scriptJava script
Java script
vishal choudhary
 
Javascript
JavascriptJavascript
Javascript
Sun Technlogies
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
WBUTTUTORIALS
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
WebVineet
 
Web Technology Part 3
Web Technology Part 3Web Technology Part 3
Web Technology Part 3
Thapar Institute
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
Ganesh Chavan
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptx
karthiksmart21
 
BITM3730Week6.pptx
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptx
MattMarino13
 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
Thinkful
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
koppenolski
 
Javascript libraries
Javascript librariesJavascript libraries
Javascript libraries
Dumindu Pahalawatta
 
Ajax Overview by Bally Chohan
Ajax Overview by Bally ChohanAjax Overview by Bally Chohan
Ajax Overview by Bally Chohan
WebVineet
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
ssuser0a07a1
 
Applied component i unit 2
Applied component i unit 2Applied component i unit 2
Applied component i unit 2Pramod Redekar
 

Similar to javaScript and jQuery (20)

Ajax
AjaxAjax
Ajax
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
Ajax
AjaxAjax
Ajax
 
Ajax workshop
Ajax workshopAjax workshop
Ajax workshop
 
Java script
Java scriptJava script
Java script
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Web Technology Part 3
Web Technology Part 3Web Technology Part 3
Web Technology Part 3
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptx
 
Ajax
AjaxAjax
Ajax
 
BITM3730Week6.pptx
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptx
 
Build a game with javascript (april 2017)
Build a game with javascript (april 2017)Build a game with javascript (april 2017)
Build a game with javascript (april 2017)
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 
Javascript libraries
Javascript librariesJavascript libraries
Javascript libraries
 
Ajax Overview by Bally Chohan
Ajax Overview by Bally ChohanAjax Overview by Bally Chohan
Ajax Overview by Bally Chohan
 
AJAX.pptx
AJAX.pptxAJAX.pptx
AJAX.pptx
 
Html5 n css3
Html5 n css3Html5 n css3
Html5 n css3
 
Applied component i unit 2
Applied component i unit 2Applied component i unit 2
Applied component i unit 2
 

Recently uploaded

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

javaScript and jQuery

  • 2. Why Study JavaScript? • JavaScript is one of the 3 languages all web developers must learn: • 1. HTML to define the content of web pages • 2. CSS to specify the layout of web pages • 3. JavaScript to program the behavior of web pages
  • 3. JavaScript Display Possibilities • JavaScript can "display" data in different ways: • Writing into an HTML element, using innerHTML. • Writing into the HTML output using document.write(). • Writing into an alert box, using window.alert(). • Writing into the browser console, using console.log().
  • 4. JavaScript Keywords • Break • Continue • Debugger • Do..while • For • function • If ….else • Return • Switch • Try…..catch • var
  • 5. JavaScript Values • The JavaScript syntax defines two types of values: Fixed values and variable values. • Fixed values are called literals. • Example: 10.50, “Johan Doe” • Variable values are called variables. • Example: var x = 6;
  • 6. JavaScript Comments • JavaScript comments can be used to explain JavaScript code, and to make it more readable. • Single Line Comments • Single line comments start with //. • Multi-line Comments • Multi-line comments start with /* and end with */.
  • 7. JavaScript Variables • JavaScript variables are containers for storing data values. • Example: • var x = 5; var y = 6;
  • 8. JavaScript Type Operators Operator Description typeof Returns the type of a variable instanceof Returns true if an object is an instance of an object type
  • 9. Data Types • String • Number • Boolean • Undefined • Null • Array • Object
  • 10. JavaScript Functions • A JavaScript function is a block of code designed to perform a particular task. • Example: • function myFunction(p1, p2) { return p1 * p2; }
  • 11. JavaScript Objects • You have already learned that JavaScript variables are containers for data values. • Objects are variables too. But objects can contain many values. • var car = {type:"Fiat", model:"500", color:"white"};
  • 12. JavaScript Function Scope • In JavaScript there are two types of scope: • Local scope • Global scope
  • 13. JavaScript Events • An HTML event can be something the browser does, or something a user does. • Here are some examples of HTML events: • An HTML web page has finished loading • An HTML input field was changed • An HTML button was clicked • <element event='some JavaScript'>
  • 14. JavaScript Math Object • Math.round() • Math.pow() • Math.sqrt() • Math.abs() • Math.ceil() • Math.floor() • Math.sin() • Math.cos() • Math.min() and Math.max() • Math.random()
  • 15. JavaScript Arrays • JavaScript arrays are used to store multiple values in a single variable. • Example: • var cars = ["Saab", "Volvo", "BMW"];
  • 16. Popping and Pushing • The pop() method removes the last element from an array: • var fruits = ["Banana", "Orange", "Apple", "Mango"]; • fruits.pop(); • The push() method adds a new element to an array (at the end): • var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi");
  • 17. JavaScript Errors - Throw and Try to Catch • The try statement lets you test a block of code for errors. • The catch statement lets you handle the error. • The throw statement lets you create custom errors. • The finally statement lets you execute code, after try and catch, regardless of the result.
  • 18. JavaScript Best Practices • Avoid global variables, • avoid new, • avoid ==, • avoid eval()
  • 19. JavaScript Versions Year Name Description 1997 ECMAScript 1 First Edition. 1998 ECMAScript 2 Editorial changes only. 1999 ECMAScript 3 Added Regular Expressions. Added try/catch. ECMAScript 4 Was never released. 2009 ECMAScript 5 Added "strict mode". Added JSON support. 2011 ECMAScript 5.1 Editorial changes. 2015 ECMAScript 6 Added classes and modules. 2016 ECMAScript 7 Added exponential operator (**). Added Array.prototype.includes.
  • 20. JavaScript JSON(JavaScript Object Notation) • JSON is a format for storing and transporting data.
  • 21. JavaScript Form Validation • HTML form validation can be done by JavaScript. • Server side validation is performed by a web server, after input has been sent to the server. • Client side validation is performed by a web browser, before input is sent to a web server.
  • 22. JavaScript Object Properties • The syntax for accessing the property of an object is: • objectName.property // person.age • or • objectName["property"] // person["age"] • Show data form Object: • for (variable in object) { code to be executed }
  • 23. Accessing Object Methods • JavaScript methods are the actions that can be performed on objects. • Example: • var person = { • firstName: "John", • fullName : function() { • return this.firstName; • } • }; • You access an object method with the following syntax: • objectName.methodName()
  • 24. JavaScript Object Constructors • function Person(first, last, age, eye) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eye; } var myFather = new Person("John", "Doe", 50, "blue"); var myMother = new Person("Sally", "Rally", 48, "green");
  • 25. JavaScript Object Prototypes • Every JavaScript object has a prototype. The prototype is also an object. • All JavaScript objects inherit their properties and methods from their prototype.
  • 26. JS Functions • Function Definitions • Function Parameters • Function Invocation • Function Call • Function Apply
  • 27. JavaScript HTML DOM Document Method Description document.getElementById(id) Find an element by element id document.getElementsByTagName(name) Find elements by tag name document.getElementsByClassName(name) Find elements by class name Finding HTML Elements
  • 28. Changing HTML Elements Method Description element.innerHTML = new html content Change the inner HTML of an element element.attribute = new value Change the attribute value of an HTML element element.setAttribute(attribute, value) Change the attribute value of an HTML element element.style.property = new style Change the style of an HTML element
  • 29. Adding and Deleting Elements Method Description document.createElement(element) Create an HTML element document.removeChild(element) Remove an HTML element document.appendChild(element) Add an HTML element document.replaceChild(element) Replace an HTML element document.write(text) Write into the HTML output stream
  • 30. Changing HTML Style • To change the style of an HTML element, use this syntax: • document.getElementById(id).style.property = new style
  • 31. HTML DOM Events • HTML DOM events allow JavaScript to register different event handlers on elements in an HTML document. • References: • https://www.w3schools.com/jsref/dom_obj_event.asp
  • 32. The addEventListener() method • The addEventListener() method attaches an event handler to the specified element. • Syntax: • element.addEventListener(event, function, useCapture);
  • 33. JavaScript Window • Two properties can be used to determine the size of the browser window. • Both properties return the sizes in pixels: • window.innerHeight - the inner height of the browser window (in pixels) • window.innerWidth - the inner width of the browser window (in pixels) • Some other methods: • window.open() - open a new window • window.close() - close the current window • window.moveTo() -move the current window • window.resizeTo() -resize the current window
  • 34. Window Screen • The window.screen object can be written without the window prefix. • screen.width • screen.height • screen.availWidth • screen.availHeight • screen.colorDepth • screen.pixelDepth
  • 35. JavaScript Window Location • Window location can redirect any page • Example: • document.getElementById("demo").innerHTML = "Page path is " + window.location.pathname;
  • 36. JavaScript Timing Events • The two key methods to use with JavaScript are: • setTimeout(function, milliseconds) Executes a function, after waiting a specified number of milliseconds. • setInterval(function, milliseconds) Same as setTimeout(), but repeats the execution of the function continuously.
  • 37. What is AJAX? • AJAX = Asynchronous JavaScript And XML. • AJAX is not a programming language. • AJAX just uses a combination of:  A browser built-in XMLHttpRequest object (to request data from a web server)  JavaScript and HTML DOM (to display or use the data)
  • 38. AJAX - The XMLHttpRequest Object • All modern browsers support the XMLHttpRequest object. • Systax: • variable = new XMLHttpRequest();
  • 39. AJAX - Send a Request To a Server • The XMLHttpRequest object is used to exchange data with a server. • xhttp.open("GET", "ajax_info.txt", true); xhttp.send(); Method Description open(method, url, async) Specifies the type of request method: the type of request: GET or POST url: the server (file) location async: true (asynchronous) or false (synchronous) send() Sends the request to the server (used for GET) send(string) Sends the request to the server (used for POST)
  • 40. GET or POST? • GET is simpler and faster than POST, and can be used in most cases. • However, always use POST requests when:  A cached file is not an option (update a file or database on the server).  Sending a large amount of data to the server (POST has no size limitations).  Sending user input (which can contain unknown characters), POST is more robust and secure than GET.
  • 41. AJAX - Server Response Property Description onreadystatechange Defines a function to be called when the readyState property changes readyState Holds the status of the XMLHttpRequest. 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready status 200: "OK" 403: "Forbidden" 404: "Page not found" For a complete list go to the Http Messages Reference statusText Returns the status-text (e.g. "OK" or "Not Found")
  • 42. jQuery • jQuery is a JavaScript Library. • jQuery greatly simplifies JavaScript programming. • jQuery is easy to learn.
  • 43. jQuery Selectors • jQuery selectors are one of the most important parts of the jQuery library. • Example: • Element Name/Tag Name • Id • Class
  • 44. jQuery Effects - Hide and Show • Example: • $(selector).hide(speed,callback); $(selector).show(speed,callback);
  • 45. jQuery Effects - Fading • With jQuery you can fade elements in and out of visibility. • $(selector).fadeIn(speed,callback); • $(selector).fadeOut(speed,callback); • $(selector).fadeToggle(speed,callback); • $(selector).fadeTo(speed,opacity,callback);
  • 46. jQuery Effects - Sliding • jQuery has the following slide methods: • slideDown() • slideUp() • slideToggle()
  • 47. jQuery - Get Content and Attributes • Three simple, but useful, jQuery methods for DOM manipulation are: text() - Sets or returns the text content of selected elements html() - Sets or returns the content of selected elements (including HTML markup) val() - Sets or returns the value of form fields
  • 48. jQuery - Remove Elements • To remove elements and content, there are mainly two jQuery methods: • remove() - Removes the selected element (and its child elements) • empty() - Removes the child elements from the selected element
  • 49. jQuery - Get and Set CSS Classes • jQuery has several methods for CSS manipulation. We will look at the following methods: • addClass() - Adds one or more classes to the selected elements • removeClass() - Removes one or more classes from the selected elements • toggleClass() - Toggles between adding/removing classes from the selected elements • css() - Sets or returns the style attribute