HTML,CSS,Bootstrap_and _JQuery
HTML,CSS,Bootstrap_and _JQuery
1. HTML
2. CSS
3. Java script
The content present on the web page The content present on the web page can
cannot be modified at runtime. be modified at runtime.
There is no interaction with the database. The website can interact with the database.
The same content gets loaded every time. The content that gets loaded may vary as
per requirements.
HTML:
• HTML: Hyper Text Mark up Language
○ Mark up Language: It is a way in which the documents are annotated such that it can be
systematically distinguished from the normal text.
• HTML is a set of mark up symbols intended for displaying content on the Internet.
• Mark up tells browsers how to display the content of a webpage, that is, the words and images.
Mark ups are commonly known as tags.
• The HTML file is broken into small parsing elements called Tokens, which are read by the
browser.
Structure of HTML
• HTML (Container): A container that holds the content and the information about the content
• Body: Content
Commonly used HTML Tags:
<h1></h1>...<h6></h6>
<p></p>
<a></a>
<span></span>
<div></div>
<select></select>
<table></table>
<img />
<br />
<input />
<hr />
Tag Structure:
An HTML entity is basically a text that starts with an ampersand (&) and ends with a semicolon (;).
These entities are often used to display the reserved characters. I.e. the characters which otherwise
would be interpreted as simple HTML: code.
< < It is used to represent the opening tag or less than sign.
> > It is used to represent the closing tag or greater than sign.
You will notice few tags have end tag and few do not.
Few will allow next contents to be plotted beside and few do not.
<span> <div>
<b> <p>
<i> <hr>
<em> <table>
<a> <ul>
<img> <ol>
<button> … <form>
You can see the entire list here. You can see the entire list here.
https://developer.mozilla.org/en- https://developer.mozilla.org/en-
US/docs/Web/HTML/Inline_elements US/docs/Web/HTML/Block-level_elements
HTML Tables
Table Structure:
<body>
<table align=”right”>
<thead>
<tr>
<th>Fruit</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apples</td>
<td>10</td>
</tr>
<tr>
<td>Oranges</td>
<td>15</td>
</tr>
</tbody>
</table>
</body>
Forms
Code Example:
<html>
<head>
<title>Log In</title>
</head>
<body>
<form action=“/action-page.php” method=“get” target=“_blank”>
<label for=“name”>Username:</label>
<input type=“text” name=“name” id=“name” />
<label for=“password”>Password:</label>
<input type=“password” name=“password” id=“password” />
GET POST
Form data IS VISIBLE in the URL. Form data is NOT VISIBLE in the URL.
Clicking the back button will not re- Clicking the back button will re-submit
submit the data; hence, it is harmless. the data; hence, you need to be cautious
while using POST.
The length of the URL is restricted. There are no restrictions on the length of
the URL.
<!DOCTYPE html>
<html>
<head>
<title>Introduction to HTML5</title>
</head>
<body>
<header role=“banner”>
<h1>Introduction to HTML5</h1>
</header>
<article>
<section>
</section>
</article>
Tag
Word enclosed by < and > signs
Also called as an element
All tags in HTML are pre-defined by W3C
E.g. <h1>, <p>, <table>
Types
o Opening
Used to open a data/information
E.g. <h1>, <p>, <html>
o Closing
Used to close the data/information
E.g. </h1>, </p>, </html>
o Empty
Tag having no data/content
Two ways
<tag></tag>
<tag />
E.g. <br/>, <hr/>
o Root
Tag which starts and ends the document
Is also called as Document Type or Document Tag or Document Element
E.g. <html> is root tag for html document
Attribute
o Extra information about the tag
o Attribute always present in
name=value format
E.g. <meta charset=”utf-8”>
Where
o Meta: tag
o Charset: attribute name
o Utf-8: attribute value
o A tag may have one or more attributes
o Every tag has following attributes
name: used to create query string
id: used to identify an element uniquely
style: used to write inline css
class:
HTML Structure
Has two parts
o Head
Contains extra information about the page
Tags:
title: used to set the title for the tab
script: used to add JS code in the page
style: used to add CSS code
meta: used to add more information about the page
link: used to link external documents (files)
base: used to set the base url used in the page
o Body
Contains the actual design
Categories
Textual
o Header: used to add header in page
There 6 levels
Tags: h1 to h6
H1 is the biggest while h6 is the smallest
o Paragraph (<p>): used to add a para
o Division(<div>): used to create groups of
Tags
Textual contents
Resources
o Images:
Img: used to add image
src: specify the source
alt: used to alternative text (rendered only in case of missing
source)
o Audio
Audio: used to play audio
controls: to render controls
autoplay: to play the file automatically
src: to set the file to play
o Video
Video: used to play video
controls: to render controls
autoplay: to play the file automatically
src: to set the file to play
List
o Unordered list
Does not render the order
Syntax:
<ul>
<li>list item1</li>
<li>list item2</li>
</ul>
o Ordered list
Renders the list item order
Syntax:
<ol>
<li>list item1</li>
<li>list item2</li>
</ol>
o Definition list
Used to create list of definitions
Syntax:
<dl>
<dt>term 1</dt>
<dd>definition 1</dd>
<dt>term 2</dt>
<dd>definition 2</dd>
</dl>
Table
o Used to create tabular representation
o Divided into 3 sections
Header
Use <thead> (table header)
Body
Use <tbody> (table body)
Footer
Use <tfoot> (table footer)
o To create row
Use <tr>
o To create column
In header
Use <th> (table header column)
In Body and Footer
Use <td> (table data)
o E.g.
<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
</tr>
</tfoot>
</table>
Attributes:
o border: used to create border
o colspan: used to merge multiple columns horizontally
o rowspan: used to merge multiple columns vertically
Linking (anchor)
o Used to link
multiple pages
<a href=”page.html”>text</a>
multiple sections within same page
<a href=”#top”>text</a>
multiple pages with multiple sections
<a href=”page#section”>text</a>
Form
o Used to get inputs from user
o Tags
Input: used to get input
type
o text: textual value
o number: number value
o email: email value
o tel: telephone
o date: date input
o time: time input
o radio: create radio button
o checkbox: multiple selection
o password: masked characters
o submit: to submit values
o reset: to clear the form
o file: used to upload file
textarea: used to get multi-line input
select: used to render drop-down
<select>
<option>op1</option>
<option>op2</option>
</select>
GET vs POST
GET POST
1. values will be sent using Request 1. Values will be sent using Request
head Body
2. Values will be appended on url 2. Values will be invisible
(visible)
3. Restriction on maximum size of data 3. There is no restriction on size of
to be passed data
4. Only ascii values can be sent using 4. Any value of any type (binary) can
GET be sent by using POST
5. URL can be bookmarked with the 5. URL can be bookmarked without
values the values
6. Files can NOT sent using GET 6. Files can be using POST
Basics of CSS
• It helps you to define how the elements should look, where they should be placed and whether
they should be displayed or not.
• It also helps you to define how elements should look on different devices.
Syntax:
CSS3
Cascading Stylesheet Style
Sequence of styles
o Browser default CSS (black)
o External CSS (red)
o Internal CSS (blue)
o Inline CSS (brown)
Terminology
CSS property: pre-defined properties provided by CSS
Declaration:
o Pair of css property and its value
o Colon(:) is used to separate the property and its value
o To terminate a declaration use semi-colon(;)
Declaration block:
o Collection of declarations
o Use {} to create a block
Selector:
o Used to select a type of element(s)
Rule/Ruleset:
o Pair of selector and a declaration block
Units
px: pixels
%: with respect to its parent
em: emphasis
o by default the em is considered as 1 (browser default)
deg: degree
s: seconds
CSS Types
Inline CSS
o Use style attribute of a tag
o Disadvantages:
Needs to be repeated with every tag having same decoration
Very difficult to manage (modify)
o This is discouraged
o E.g.
<p style=”color:red”>test</p>
Internal CSS
o Use style tag in Head section
o Advantage:
Simpler than inline
Easy to manage
o Disadvantage:
Repeated in multiple pages of a website
o E.g.
<style>
p{
color:red;
}
</style>
External CSS
o CSS rules can be written outside the page (in an external file with .css extension)
o To attach/link external css with a page use link tag in Head section
<link rel=”stylesheet” href=”<css file name>”>
o Advantages:
Single external css file can be used across multiple pages
Browser Default CSS
o Available in every browser
Selector Types
Type / Element Selector
o Used to select similar type of element(s)
o E.g.
p {
color: red;
}
only paragraphs will have red color
Multiple type/element selector (,)
o Used to select multiple type of elements
o Comma (,) is used to create multiple type selector
o E.g.
p, div {
color: red;
}
both paragraph(s) and division(s) will have red color
Id Selector (#)
o Used to select an element having specified id
o Hash(#) is used to create an id selector
o E.g.
div#div1 {
color:red
}
only div having id div1 will have color red
#product1 {
color:red
}
any element having id product1 will have color red
Class Selector (.)
o Used to select element(s) having same class
o Dot (.) is used to create a class selector
o E.g.
div.div1 {
color:red
}
only div having class div1 will have color red
.product1 {
color:red
}
any element having class product1 will have color red
Descendant selector (white-space)
o Used when elements have relationships
o Used to select child elements at any level
o Space is used to create descendant selector
E.g.
body p {
color:red;
}
every element inside body will have red color
Child selector (>)
o Used when elements have relationships
o Used to select child elements at first level (direct child element(s))
o > is used to create descendant selector
E.g.
body > p {
color:red;
}
Paragraph(s) declared under body will have red color
Universal selector (*)
o Used to select All type of elements in a page(s)
o Use * to create universal selector
o E.g.
*{
font-family: Arial;
}
all element(s) in the page will have font family set to Arial
Attribute selector
o Used to select element(s) based on the attribute
o Use [] to write the criteria
o E.g.
input[type=”submit”] {
Color: red;
}
only input having type = “submit” will have color set to red
Pseudo selector
CSS Position
Used to decide the position of the element
Values
o Static:
default value
top, left, right and bottom will be ignored
o Relative
Relative its static/default position
top, left, right and bottom will be applied by using its original (static) position
o Absolute
Top, left, right and bottom will be applied by using browser’s origin
Gets scrolled with page
o Fixed
Top, left, right and bottom will be applied by using browser’s origin
Never gets scrolled
CSS Float
Used to decide the position (left and right)
To clear/cancel the effect of floating use clear property
CSS3 properties
Shadow:
o Values:
Vertical
Horizontal
Blur
Color
o Types
Text:
text-shadow : 2px 2px 5px red;
Box
box-shadow : 2px 2px 5px red;
Border radius
o Used to add rounded corners to any element
o E.g. border-radius: 10px;
o Trick:
Apply ½ of width to border radius to convert square element into circle shape
Transform:
o Used to transform an element
o Types
Rotate: rotate element
transform: rotate(45deg);
Scale: scale element (zoom)
transform: scale(2);
Translate: move position
transform: translate(10px, 10px);
Transition:
o Used to animation (duration in seconds)
o E.g. transition: all 2s;
Gradients
o Used to add multiple colors (blended)
o Types
Linear
E.g. background: linear-gradient(red, yellow);
Radial
E.g. background: radial-gradient(red, yellow);
Columns
o Used to distribute the element contents in multiple columns
o E.g. column-count: 3;
At (@) rules:
o Start with @ symbol
o Font:
Used to load custom fonts
E.g.
@font-face {
font-family: <family name>;
src: url(‘<path>’);
}
p{
font-family: <family name>;
}
o Media Query
Used to create responsive website
A website is having an ability to optimize output according to the device width
Desktop
Tablet
Mobile
E.g.
@media screen and (max-height:768px) {
h1 {
color: red;
}
}
will have h1 with color red only on mobile devices
Ways to apply Style:
• Inline stylesheet: This is a CSS that is directly applied to an element inside HTML code.
• Internal stylesheet: This is a CSS that is applied inside a file but not inside an element. It is
generally added inside the <style> tag, which is contained within the <head> tag.
• External stylesheet: This is a CSS that is applied from an external file. This external file is referred
to inside the HTML code using the <link> tag.
• The following is the order of priority: Inline > Internal > External.
External CSS:
Responsive web design is about creating web sites which automatically adjust themselves to look good on all devices, from small
phones to large desktops.
Bootstrap Versions
Bootstrap 5 (released 2021) is the newest version of Bootstrap (released 2013); with new components, faster stylesheet
and more responsiveness.
Bootstrap 5 supports the latest, stable releases of all major browsers and platforms. However, Internet Explorer 11 and
down is not supported.
The main differences between Bootstrap 5 and Bootstrap 3 & 4, is that Bootstrap 5 has switched to vanilla JavaScript
instead of jQuery.
Note: Bootstrap 3 and Bootstrap 4 is still supported by the team for critical bugfixes and documentation changes, and it
is perfectly safe to continue to use them. However, new features will NOT be added to them.
Easy to use: Anybody with just basic knowledge of HTML and CSS can start using Bootstrap
Responsive features: Bootstrap's responsive CSS adjusts to phones, tablets, and desktops
Mobile-first approach: In Bootstrap, mobile-first styles are part of the core framework
Browser compatibility: Bootstrap 5 is compatible with all modern browsers (Chrome, Firefox, Edge, Safari,
and Opera). Note that if you need support for IE11 and down, you must use either BS4 or BS3.
You can:
JavaScript?
Bootstrap 5 uses JavaScript for different components (like modals, tooltips, popovers etc). However, if you just use the CSS part
of Bootstrap, you don't need them.
Bootstrap 5 Containers
You learned from the previous chapter that Bootstrap requires a containing element to wrap site contents.
Containers are used to pad the content inside of them, and there are two container classes available:
Fixed Container
1. Use the .container class to create a responsive, fixed-width container.
2. Note that its width (max-width) will change on different screen sizes:
Open the example below and resize the browser window to see that the container width will change at different
breakpoints:
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
Fluid Container
Use the .container-fluid class to create a full width container, that will always span the entire width of the screen
(width is always 100%):
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
Container Padding
By default, containers have left and right padding, with no top or bottom padding. Therefore, we often use spacing
utilities, such as extra padding and margins to make them look even better. For example, .pt-5 means "add a large top
padding"
Other utilities, such as borders and colors, are also often used together with containers:
Responsive Containers
You can also use the .container-sm|md|lg|xl classes to determine when the container should be responsive.
Bootstrap's grid system is built with flexbox and allows up to 12 columns across the page.
If you do not want to use all 12 columns individually, you can group the columns together to create wider columns:
span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1
span 6 span 6
span 12
The grid system is responsive, and the columns will re-arrange automatically depending on the screen size.
Make sure that the sum adds up to 12 or fewer (it is not required that you use all 12 available columns).
Grid Classes
The classes above can be combined to create more dynamic and flexible layouts.
Tip: Each class scales up, so if you want to set the same widths for sm and md, you only need to specify sm
<!-- Control the column width, and how they should appear on different devices -->
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
First example: create a row (<div class="row">). Then, add the desired number of columns (tags with appropriate
.col-*-* classes). The first star (*) represents the responsiveness: sm, md, lg, xl or xxl, while the second star
represents a number, which should add up to 12 for each row.
Second example: instead of adding a number to each col, let bootstrap handle the layout, to create equal width
columns: two "col" elements = 50% width to each col, while three cols = 33.33% width to each col. Four cols = 25%
width, etc. You can also use .col-sm|md|lg|xl|xxl to make the columns responsive.
<div class="row">
<div class="col">.col</div>
<div class="col">.col</div>
<div class="col">.col</div>
</div>
Responsive Columns
The following example shows how to create four equal-width columns starting at tablets and scaling to extra large desktops. On
mobile phones or screens that are less than 576px wide, the columns will automatically stack on top of each other:
<div class="row">
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
</div>
Bootstrap 5 has some contextual classes that can be used to provide "meaning through colors".
The classes for text colors are: .text-muted, .text-primary, .text-success, .text-info, .text-warning, .text-
danger, .text-secondary, .text-white, .text-dark, .text-body (default body color/often black) and .text-
light:
Background Colors
The classes for background colors are: .bg-primary, .bg-success, .bg-info, .bg-warning, .bg-danger, .bg-
secondary, .bg-dark and .bg-light.
The .bg-color classes above does not work well with text, or atleast then you have to specify a proper .text-color
class to get the right text color for each background.
However, you can use the .text-bg-color classes and Bootstrap will automatically handle the appropriate text color
for each background color:
Boostarp 5 Tables
Basic Table
Striped Rows
Bordered Table
The .table-bordered class adds borders on all sides of the table and cells:
Hover Rows
The .table-hover class adds a hover effect (grey background color) on table rows:
Black/Dark Table
Contextual Classes
Contextual classes can be used to color the whole table (<table>), the table rows (<tr>) or table cells (<td>).
Class Description
.table-primary Blue: Indicates an important action
.table-success Green: Indicates a successful or positive action
.table-danger Red: Indicates a dangerous or potentially negative action
.table-info Light blue: Indicates a neutral informative change or action
.table-warning Orange: Indicates a warning that might need attention
.table-active Grey: Applies the hover color to the table row or table cell
.table-secondary Grey: Indicates a slightly less important action
Class Description
.table-light Light grey table or table row background
.table-dark Dark grey table or table row background
You can also use any of the contextual classes to only add a background color to the table header:
Responsive Tables
The .table-responsive class adds a scrollbar to the table when needed (when it is too big horizontally):
<div class="table-responsive">
<table class="table">
...
</table>
</div>
You can also decide when the table should get a scrollbar, depending on the screen width:
Boostarp 5 Images
Rounded Corners
Circle
Thumbnail
Responsive Images
Images come in all sizes. So do screens. Responsive images automatically adjust to fit the size of the screen.
Create responsive images by adding an .img-fluid class to the <img> tag. The image will then scale nicely to the
parent element.
The .img-fluid class applies max-width: 100%; and height: auto; to the image:
Boostarp 5 buttons
The button classes can be used on <a>, <button>, or <input> elements:
Boostarp 5 Dropdowns
To open the dropdown menu, use a button or a link with a class of .dropdown-toggle and the data-bs-
toggle="dropdown" attribute.
Add the .dropdown-menu class to a <div> element to actually build the dropdown menu. Then add the .dropdown-
item class to each element (links or buttons) inside the dropdown menu.
Boostarp 5 Navbar
Basics of Java script
• JavaScript (JS) is the programming language of web development. It was initially used to ‘make
web pages alive’.
• Unlike Java, scripts do not require any compilation to run. JS can execute on a browser, a server
and any device that has a ‘JavaScript Engine’.
• JS does not provide low-level access to memory or CPU, which is why it is a ‘safe’ programming
language.
• Adding or modifying HTML content on a page, including, but not restricted to, showing/hiding
elements as well as changing the size, style and HTML attributes
• Reacting to user actions such as hovering, mouse clicks, key presses, etc.
• Sending requests to remote servers over the network and saving the data on the client side.
• JavaScript (JS) can be placed either internally in an HTML file using the <script> tag, where you
can write all the scripts inside the <script> tag, or externally in a JavaScript file (that ends with a
‘.js’ extension), which can be added as a source in the <script> tag.
• The <script> tag can be placed either in the <head> or in the <body> part of the HTML
document.
• However, because JS is a render blocker, it is preferable to call these scripts in the <body> tag
after all the HTML elements are rendered.
JavaScript
Data Types
All data types in JS are inferred
Automatically decided by JS by looking at the variable’s CURRENT value
Types
o Number:
used to keep both integer and float values
E.g.
num = 100;
salary = 10.15;
o String:
E.g.
firstName = “steve”;
firstName = ‘steve’;
o Boolean:
Can have only true or false value
E.g.
canVote = true;
o undefined
o object
Everything in JS is an object
Functions are also considered objects
Pre-Defined Objects
console: used to represent the browser console
window: used to represent the browser GUI
document:
Pre-Defined Values
NaN: Not a Number
o “test” * “test1” = NaN
o data type: number
Infinity:
o Only when a number is divided by zero (0)
undefined
Function
function keyword is used to define a function
function declaration and definitions CAN NOT separated
Syntax:
function <function name>(<param list>) {
// function body here
}
IMP
o Function can not supply the param data type
o There is no change in function signature (prototype) even if the function is returning a value
return keyword is used to return a value
o function CAN NOT decide the number of parameters and data type of parameters
function function1(n1) {
// body
}
// n1 is declared as undefined
function1();
function test() {
console.log(this);
}
test();
In case if the function is called by using an object then the object becomes this
function test() {
console.log(this);
}
// prints
// p object {…}
Function Alias
o Another name given to a function
o Variable of type function
o E.g.
function function1() {}
// function alias
var myfunction1 = function1;
myfunction1();
Anonymous Function
o Function without a name
o E.g.
Array
Collection of objects
May contain similar or dis-similar objects (values)
o E.g.
var array = [1, 2, 3, 4]
var array = [1, “test”, 2, true, false, “test2”, 3, 4]
to print / process all members in the array
for (var index = 0; index < array.length; index++ )
// code here
}
to manipulate the values
o push: to add a value at the last position
o pop: to remove the last element from array
o splice: to remove an item at an index
Variable Scope
Local scope:
o Declare a variable with var keyword
o Function parameters are ALWAYS declared as local variables
o E.g.
function function1 () {
// local
var num = 100;
}
Global scope:
o Declare a variable without using var keyword
o Global variables CAN be declared inside a function
o E.g.
// global
salary = 10.15;
function function1 () {
// global
num = 100;
}
Conversion
string to number:
o parseInt()
converts string to number in integer format
E.g.
parseInt(“10.20”); // 10
o parseFloat()
converts string to number in float format
E.g.
parseInt(“10.20”); // 10.20
number to string:
o E.g.
“” + 20; // “20” (string)
‘’ + 20; // “20” (string)
JSON
JavaScript Object Notation
Types
o Object
Collection of Key-value pairs separated by Comma(,)
Use {}
E.g.
var movie = {
“title”: ”cars”,
“price”: 30
}
Where title and price are keys while cars and 30 are values
To access values
console.log(“title: “ + movie.title);
console.log(“price: “ + movie.price);
o Array
Collection of objects
Use []
E.g.
var movies = [
{ “title”:”cars”, “price”: 30 },
{ “title”:”moana”, “price”: 40 }
]
• JavaScript (JS) programs are a list of programming instructions called statements that are
executed by web browsers.
• JS statements consist of values, operators, expressions, keywords and comments. They are
executed in a waterfall fashion, that is, one by one, in the order in which they are written.
• Generally, a JavaScript (JS) code consists of statements with variables that store values or
expressions.
var total = num1 + num2; //Computing expressions and storing result in variable
• In a programming language, variables are used to store data values. In JS, variables are declared
using the var keyword. An equal sign (‘=’) is used to assign value to the variables.
• JS values can be strings, numbers, arrays, objects, booleans or expressions. String values need to
be written within single or double quotes, for example, ‘John Doe’ or “John Doe”, and number
values should not be written within quotes, for example, 2 or 200.45.
• JS operators can be used to compute values; e.g.,
• For single-line JS comments, you can use “//”, and for multiline comments, you can use “/* */”.
• JavaScript (JS) programs are a list of programming instructions called statements that are
executed by web browsers.
• JS statements consist of values, operators, expressions, keywords and comments. They are
executed in a waterfall fashion, that is, one by one, in the order in which they are written.
• JS statements end with a semicolon (‘;’). Semicolons essentially separate JS statements. It is not
mandatory to add a semicolon, but it is highly recommended. Using semicolons, you can add
multiple JS statements in one line. For example,
• JS ignores multiple spaces. However, it is recommended to add white spaces to your code to
make it more readable. For example,
• A best practice is to avoid having more than 80 characters in one line for better readability. The
best place to break a JS code to a new line is immediately after the operator.
• JavaScript (JS) variables are containers for storing data values. In earlier examples, you learnt
that variables can store values and expressions.
• All JS variables must be identified with a unique name called identifier. The rules for writing an
identifier name are as follows:
• Names can contain letters, digits, the dollar sign (‘$’) and the underscore sign (‘_’).
• https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar
• The best practice is to not keep a name, such as x, y, z, that does not indicate the meaning or
significance of that variable. The identifier name should signify the meaning of the variable; for
example, name and age.
• In JS, you can assign a value to the variable using the ‘=’ operator.
OOP JavaScript
Everything in JS is an Object, even functions are also considered as objects
collection of properties and functions/methods
To create an object/instance
o Using Object function
E.g.
var person = new Object();
person.name = “person1”; // name is a property
o Use []
function printRecord() {}
Object
Built-in function
Using Object JS allows developer to create an instance
Root function
jQuery
External JS library (collection of functions)
Open source and free library
Large community
To load jQuery js
o <script src=”js/jquery.js”></script>
To use jQuery
o Use $ to load jQuery functions
o Syntax:
$(<css selector>).<function>()
E.g.
$(‘#div1’).hide();
Introduction to jQuery
It simplifies the process of traversing HTML documents, handling events, animating elements, and AJAX interactions.
Getting Started
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
Basic Syntax
The basic syntax of jQuery involves selecting elements and performing actions on them using methods.
Selectors
Common selectors include element selectors, class selectors, ID selectors, attribute selectors, etc.
// Selecting elements
$("p") // Selects all <p> elements
$(".classname") // Selects all elements with class "classname"
$("#id") // Selects the element with id "id"
$("[attribute]") // Selects all elements with a specified attribute
Actions
Once elements are selected, various actions can be performed on them using jQuery methods.
// Manipulating elements
$(selector).hide() // Hides the selected element(s)
$(selector).show() // Shows the selected element(s)
$(selector).addClass("classname") // Adds a class to the selected element(s)
$(selector).removeClass("classname") // Removes a class from the selected element(s)
$(selector).toggle() // Toggles between hide() and show()
$(selector).html(content) // Sets the HTML content of the selected element(s)
$(selector).text(content) // Sets the text content of the selected element(s)
$(selector).attr(attribute, value) // Sets attribute value of the selected element(s)
Events
// Event handling
$(selector).click(function() {
// Code to be executed when element is clicked
});
--------------------------------------------------------------------------------------
$(selector).mouseenter(function() {
// Code to be executed when mouse enters element
});
-------------------------------------------------------------------------------------
$(selector).mouseleave(function() {
// Code to be executed when mouse leaves element
});
AJAX
jQuery simplifies AJAX interactions, making it easier to load data from the server without refreshing the page.
// AJAX
$.ajax({
url: "example.json",
type: "GET",
data: { id: 1 },
success: function(response) {
// Code to be executed on successful AJAX call
},
error: function(xhr, status, error) {
// Code to be executed on AJAX error
}
});