Unit 2-Js Bootstrap J-query
Unit 2-Js Bootstrap J-query
Example:
<html>
<body>
<script language="javascript" type="text/javascript">
document.write ("Hello World!")
</script>
</body>
</html>
<script type="text/javascript">
var name;
var rollno;
</script>
Automatically Global:
• If you assign a value to a variable that has not been
declared, it will automatically become
a GLOBAL variable.
• This code example will declare a global variable price,
even if the value is assigned inside a function.
Example:
myFunction();
// code here can use price
function myFunction()
{
price = 250; //has Global scope
}
Example:
<script language="javascript" type="text/javascript">
var collegename="GEC college"; //global scope
function function1()
{
var studentname="Anand";//local scope
document.write("<center>"+studentname+"</center><br
>");
document.write("<center>"+collegename+"</center><br>
");//global scope
}
function function2()
{
var branchname="Information Technology";//local
scope
document.write("<center>"+branchname+"</center><br
>");
document.write("<center>"+collegename+"</center><br>
");//global scope
document.write("<center>"+studentname+"</center>");/
/not displayed because of local scope
}
function1();
function2();
</script>
DATA TYPES:
• JavaScript has only four types of data
▪ Numeric
▪ String
▪ Boolean
▪ Null
• Numeric :
▪ Integers such as 108 or 1120 or 2016
▪ Floating point values like 23.42, -56.01 and 2E45.
▪ No need to differentiate between.
▪ In fact variables can change type within program.
• String:
▪ A String is a Collection of character.
▪ All of the following are strings:
"Computer", "Digital" , "12345.432".
▪ Put quotes around the value to a assign a variable:
name = "Uttam K.Roy";
• Boolean:
▪ Variables can hold the values true and false.
▪ Used a lot in conditional tests (later).
9 Chapter 2 - JAVA SCRIPT,BOOTSTRAP,JQUERY
FULL STACK TECHNOLOGIES
• Null:
▪ Used when you don’ t yet know something.
▪ A null value means one that has not yet been
decided.
▪ It does not mean nil or zero and should NOT be
used in that way.
FUNCTIONS:
• A function is a group of reusable code which can be
called anywhere in your program.
• This eliminates the need of writing the same code again
and again.
• It helps programmers in writing modular codes.
Functions allow a programmer to divide a big program
into a number of small and manageable functions.
• Like any other advanced programming language,
JavaScript also supports all the features necessary to
write modular code using functions.
• We were using these functions again and again, but
they had been written in core JavaScript only once.
• JavaScript allows us to write our own functions as well.
• Function Definition
• Before we use a function, we need to define it.
• The most common way to define a function in
JavaScript is
• By using keyword function, followed by a unique
function name, a list of parameters (that might be
empty), and a statement block surrounded by curly
braces.
Syntax:
<script type="text/javascript">
function functionname(parameter-list)
{
statements
}
</script>
Example:
<html>
<head>
<title>My First JavaScript code!!!</title>
<script type="text/javascript">
function sayHello()
{
document.write("Hello Anand How
are you...?");
}
sayHello();//calling function
</script>
</head>;
<body>
</body>
</html>
Calling a Function:
To invoke a function somewhere later in the script, you
would simply need to write the name of that function as shown
in the following code.
<html>
<head>
<title>Calling a function</title>
<style type='text/css'>
{
text-align:center;
}
</style>
<script type="text/javascript">
function sayHello()
{
var name=form.name.value;
document.write("Hello "+name+" Good
Morning");
}
</script>
</head>
<body>
<p>Please enter you name and click
the button to get wishes
</p></br>
<form name='form'>
<input type='text' name='name'
placeholder='Enter Name'><br><br>
<input type='button' value='click here'
onclick='sayHello();'>
</form>
</body>
</html>
Output:
OPERATORS:
JavaScript supports the following types of operators.
• Arithmetic Operators
• Assignment Operators
• Comparison Operators
• Logical (or Relational) Operators
• Conditional (or ternary) Operators
Arithmetic Operators:
• JavaScript supports the following arithmetic operators:
• Assume variable A holds 10 and variable B holds 20,
then:
13 Chapter 2 - JAVA SCRIPT,BOOTSTRAP,JQUERY
FULL STACK TECHNOLOGIES
Assignment Operators:
Operator Description Example
Assigns the value on the
m=20
= right hand side to the
variable on left hand side
Adds the right hand side m = 20
operand to the left hand n = 10
+= side operand and assigns m+=n
the result to the left hand assigns 30 to m
side operand.
Subtracts the right hand
m = 20
side operand from the left
n=5
hand side operand and
-= m-=n
assigns the result to the left
assigns 15 to m
hand side operand.
Multiplies the right hand
m = 20
side operand and the left
n = 10
*= hand side operand and
m*=n
assigns the result to the left
assigns 200 to m
hand side operand.
Devides the left hand side
m = 20
/= operand by the right hand
n = 10
side operand and assigns
m/=n
the quotient to the left hand
assigns 2 to m
side operand.
Divides the left hand side
m = 20
operand by the right hand
n = 10
%= side operand and assigns
m%=n
the remainder to the left
assigns 0 to m
hand side operand.
Comparison Operators:
Operator Description Example
Returns true if both the
20==10 returns
== operands are equal
false
otherwise returns false
Returns true if both the
20 !=10 returns
!= operands are not equal
true
otherwise returns false
Returns true if left hand
side operand
20 > 10 returns
> Is greater than the right
true
hand side operand.
otherwise returns false
Returns true if left hand
side operand
is greater than or equal to 20 >= 10 returns
>=
the right hand side true
operand. otherwise returns
false
Returns true if left hand
side operand
20 < 10 returns
< Is less than the right hand
false
side operand. otherwise
returns false
Returns true if left hand
side operand
20 <= 10 returns
<= is less than or equal to the
false
right hand side operand.
otherwise returns false
}
else
{
block of code to be executed if the condition is false
}
Example:
<HTML>
<HEAD>
<script>
function check()
{
var age=form.age.value;
if(age>=18)
{
alert("You are eligible for vote");
}
else
{
alert("You are not eligible for vote");
}
}
</script>
</HEAD>
<BODY>
<form name='form'>
<p>Enter your age and check whether you are
eligible for vote or not?</p><br>
<input type='text' name='age'><br><br>
<input type='button' value='check eligibility'
onclick='check();'>
</form>
</BODY>
</HTML>
Output:
if (condition1)
{
block of code to be executed if condition1 is true
}
else if (condition2)
{
block of code to be executed if the condition1 is false and
condition2 is true
}
else
{
block of code to be executed if the condition1 is false and
condition2 is false
}
Example:
<HTML>
<HEAD>
<script>
function check()
{
var percentage=form.percentage.value;
if(percentage>=90&&percentage<=100)
{
alert("Your grade is A+");
}
else if(percentage>=75&&percentage<90)
{
alert("Your grade is A");
}
else if(percentage>=60&&percentage<75)
{
alert("Your grade is B");
}
else if(percentage>=40&&percentage<60)
{
alert("Your grade is C");
}
else if(percentage>100)
{
alert("Wrong details.....");
}
else
{
alert("You are failed");
}
}
</script>
</HEAD>
<BODY>
<form name='form'>
<p>Enter your marks to know your
grade</p><br>
<input type='text' name='percentage'
placeholder='EX:70.45/70'><br><br>
<input type='button' value='check grade'
onclick='check();'>
</form>
</BODY>
</HTML>
Output:
Switch Statement:
Use the switch statement to select one of many blocks of code
to be executed.
22 Chapter 2 - JAVA SCRIPT,BOOTSTRAP,JQUERY
FULL STACK TECHNOLOGIES
Syntax:
switch(expression) {
case 1:
code block
break;
case 2:
code block
break;
.
.
case n:
code block
break;
default:
default code block
}
This is how it works:
• The switch expression is evaluated once.
• The value of the expression is compared with the values
of each case.
• If there is a match, the associated block of code is
executed.
Example:
<HTML>
<HEAD>
<script>
function check()
{
var category=form.category.value;
switch(category)
{
case "SC":
alert("50 vanacies");
break;
case "OC":
alert("5 vacanices");
break;
case "BC":
alert("30 vanacies");
break;
case "ST":
alert("45 vanacies");
break;
case "OBC":
alert("20 vanacies");
break;
default:
alert("please enter valid category");
break;
}
}
</script>
</HEAD>
<BODY>
<form name='form'>
<p>Please enter your category to check no of
vacanices</p><br>
<input type='text' name='category'
placeholder='EX:OC/BC/OBC/SC/ST'><br><br>
while (condition)
{
code block to be executed
}
Example:
Write a JavaScript code to print 0 to n even numbers using
while loop.
<HTML>
<HEAD>
<script>
function check()
{
25 Chapter 2 - JAVA SCRIPT,BOOTSTRAP,JQUERY
FULL STACK TECHNOLOGIES
var number=form.number.value;
var i=1;
while(i<=number)
{
if(i%2==0)
document.write("<center>"+i+"</center><br>");
i++;
}
}
</script>
</HEAD>
<BODY>
<form name='form'>
<p>Find o to n even numbers</p><br>
<input type='text' name='number'><br><br>
<input type='button' value='Get Even Numbers'
onclick='check();'>
</form>
</BODY>
</HTML>
Output:
do
{
code block to be executed
}while (condition);
The for Loop: The for loop has the following syntax:
for (initialization; condition; iteration)
{
code block to be executed
}
Statement 1 is executed before the loop (the code block)
starts.
Statement 2 defines the condition for running the loop (the
code block).
Statement 3 is executed each time after the loop (the code
block) has been executed.
Example 2:
<HTML>
<HEAD>
<script>
function check()
{
var number=form.number.value;
var fact=1;
for(var i=1;i<=number;i++)
{
fact=fact*i;
}
alert("factorial of "+number+"is "+fact);
}
</script>
</HEAD>
<BODY>
<form name='form'>
<p>Enter a number to know the
factorial</p><br>
<input type='text' name='number'><br><br>
<input type='button' value='Get Factorial'
onclick='check();'>
</form>
</BODY>
</HTML>
Output:
HTML DOM
The way document content is accessed and modified is called
the Document Object Model, or DOM.
In the HTML DOM (Document Object Model), everything is
a node:
• The document itself is a document node
• All HTML elements are element nodes
• All HTML attributes are attribute nodes
• Text inside HTML elements are text nodes
• Comments are comment nodes
The Objects are organized in a hierarchy. This hierarchical
structure applies to the organization of objects in a Web
document.
• Window object − Top of the hierarchy. It is the
outmost element of the object hierarchy.
• Document object − Each HTML document that gets
loaded into a window becomes a document object. The
document contains the contents of the page.
• Form object − Everything enclosed in the
<form>...</form> tags sets the form object.
• Form control elements − The form object contains all
the elements defined for that object such as text fields,
buttons, radio buttons, and checkboxes.
Here is a simple hierarchy of a few important objects −
Properties
alinkColor The color of active links
-
bgColor Sets the background color of the web page. It is
- set in the <body> tag. The following code sets the
background color to white.
document.getElementById("header");
Properties
• defaultStatus - This is the default message that is loaded
into the status bar when the window loads.
• opener The object that caused the window to open.
• status - The status bar is the bar on the lower left side of
the browser and is used to display temporary messages
• length - The number of frames that the window contains.
Methods
• alert("message") - The string passed to the alert function is
displayed in an alert dialog box.
• open("URLname","Windowname",["options"]) - A new
window is opened with the name specified by the second
parameter.
• close() - This function will close the current window or the
named window.
• confirm("message") The string passed to the confirm
function is displayed in the confirm dialog box.
• prompt("message","defaultmessage") - A prompt dialog box
is displayed with the message passed as the prompt
question or phrase.
Example:
<HTML>
<HEAD>
<script>
function funalert()
{
window.alert("Hello be alert....");
}
function funopen()
{
window.open("http://www.gmail.com");
}
function funprompt()
{
window.prompt("Do you want to exit?");
}
function funconfirm()
{
window.confirm("Do you want to exit?");
}
function funclose()
{
window.close();
}
</script>
</HEAD>
<BODY>
<form>
<input type='button' value='click here for alert()'
onclick='funalert()'>
<input type='button' value='click here for open()'
onclick='funopen()'>
<input type='button' value='click here for
prompt()' onclick='funprompt()'>
<input type='button' value='click here for
cofirm()' onclick='funconfirm()'>
<input type='button' value='click here for close()'
onclick='funclose()'>
</form>
</BODY>
</HTML>
Output:
FORM OBJECT:
Properties
• action - The action attribute of the Top of Form element
• length - Gives the number of form controls in the form
• method- The method attribute of the Top of Form element
• name - The name attribute of the Top of Form element
• target - The target attribute of the Top of Form element
Methods
• reset()- Resets all form elements to their default values
• submit()- Submits the form
Properties of Form Elements
document.write("<center>"+str.toLowerCase()+"</center
>");
document.write("<center>"+str.lastIndexOf("locate")+"</
center>");
document.write("<center>"+str.split(" ")+"</center>");
document.write("<center>"+str.substr(5,10)+"</center>"
);
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
Output:
ARRAY OBJECT:
The Array object is used to store multiple values in a single
variable.
Properties:
• length - Sets or returns the number of elements
in an array
Methods:
• concat() - Joins two or more arrays, and returns a copy
of the joined arrays
• indexOf() - Search the array for an element and returns
its position
• join() - Joins all elements of an array into a string
• lastIndexOf() - Search the array for an element, starting
at the end, and returns its position
• pop() - Removes the last element of an array, and
returns that element
• push()- Adds new elements to the end of an array, and
returns the new length
• reverse() - Reverses the order of the elements in an
array
• shift() - Removes the first element of an array, and
returns that element
• slice() - Selects a part of an array, and returns the new
array
• sort() - Sorts the elements of an array
• splice() - Adds/Removes elements from an array
• toString() - Converts an array to a string, and
returns the result.
Example:
<HTML>
<HEAD>
<script>
var cars = new Array("Saab", "Volvo", "BMW");
var bikes = new Array("Pulsar", "Honda", "FZ");
document.write("<center>"+cars.concat(bikes)+
"</center>");
40 Chapter 2 - JAVA SCRIPT,BOOTSTRAP,JQUERY
FULL STACK TECHNOLOGIES
document.write("<center>"+cars.indexOf("Volvo"
)+"</center>");
bikes.push("Bajaj");
document.write("<center>"+bikes+"</center>");
bikes.reverse();
document.write("<center>"+bikes+"</center>");
cars.sort();
document.write("<center>"+cars+"</center>");
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
Output:
Example:
<HTML>
<HEAD>
<script>
var d=new Date();
document.write("<center>"+d.getDate()+"</center>");
document.write("<center>"+d.getDay()+"</center>");
document.write("<center>"+d.getHours()+"</center>");
document.write("<center>"+d.getMinutes()+"</center>");
document.write("<center>"+d.getMonth()+"</center>");
document.write("<center>"+d.getYear()+"</center>");
document.write("<center>"+d.getTime()+"</center>");
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
Output:
EVENT HANDLING:
JavaScript is an Event Driven System
Event:
An Event is “ any change that the user makes to the state of
the browser”
There are 2 types of events that can be used to trigger script:
1. Window Events
2. User Events
1. Window Events, which occurs when
• A page loads or unloads
• Focus is being moved to or away from a window or
frame
• After a period of time has elapsed
2. User Events, which occur when the user interacts with
elements in the page using mouse or a keyboard.
Event Handlers:
Event handlers are Javascript functions which you
associate with an HTML element as part of its definition in the
HTML source code.
Syntax: <element attributes
eventAttribute=” handler” >
44 Chapter 2 - JAVA SCRIPT,BOOTSTRAP,JQUERY
FULL STACK TECHNOLOGIES
Attribute Description
Onblur The input focus is moved from the object
The value of a field in a form has been
Onchange changes by the user by entering or deleting
data
Onclick Invoked when the user clicked on the object.
Invoked when the user clicked twice on the
Ondblclick
object.
Onfocus Input focus is given to an element
Invoked when a key was pressed over an
Onkeydown
element.
Invoked when a key was pressed over an
Onkeypress
element then released.
Invoked when a key was released over an
Onkeyup
element.
Onload When a page is loaded by the browser
The cursor moved over the object and
Onmousedown
mouse/pointing device was pressed down.
The cursor moved while hovering over an
Onmousemove
object.
Onmouseout The cursor moved off the object
The cursor moved over the object (i.e. user
onmouseover
hovers the mouse over the object).
The mouse/pointing device was released after
Onmouseup
being pressed down.
A window is moved, maximized or restored
Onmove
either by the user or by the script
A window is resized by the user or by the
Onresize
script
2. <html>
<head>
<script language="javascript">
function fun()
{
alert("You Clicked on Button");
}
</script>
</head>
<body>
<input type="button" value="Click Me" onClick="fun()">
</body>
</html>
Output:
<HTML>
<HEAD>
<script>
function check()
{
var number=form.number.value;
var i=1;
while(i<=number)
{
if(i%2==0)
document.write("<center>"+i+"</center><br>");
i++;
}
}
</script>
</HEAD>
<BODY>
<form name='form' onSubmit='check();'>
<p>Find 1 to n even numbers</p><br>
<input type='text' name='number'><br><br>
<input type='submit' value='Get Even Numbers'>
</form>
</BODY>
</HTML>
Output:
Math Object:
The math object provides you properties and methods for
mathematical constants and functions. Unlike other global
objects, Math is not a constructor. All the properties and
methods of Math are static and can be called by using Math as
an object without creating it.
Example:
<HTML>
<HEAD>
<script>
document.write("<center>"+Math.PI+"</center><br>");
document.write("<center>"+Math.ceil(0.991)+"</center><br>");
document.write("<center>"+Math.floor(0.991)+"</center><br>")
;
51 Chapter 2 - JAVA SCRIPT,BOOTSTRAP,JQUERY
FULL STACK TECHNOLOGIES
document.write("<center>"+Math.min(12,3,42,55,75,1)+"</cen
ter><br>");
document.write("<center>"+Math.max(12,3,42,55,75,1)+"</ce
nter><br>");
document.write("<center>"+Math.pow(5,3)+"</center><br>");
document.write("<center>"+Math.sqrt(25)+"</center><br>");
document.write("<center>"+Math.random()+"</center><br>");
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
Output:
Form Validation:
Form validation normally used to occur at the server,
after the client had entered all the necessary data and then
pressed the Submit button. If the data entered by a client was
incorrect or was simply missing, the server would have to
send all the data back to the client and request that the form
be resubmitted with correct information. This was really a
lengthy process which used to put a lot of burden on the
server.
JavaScript provides a way to validate form's data on the
client's computer before sending it to the web server. Form
validation generally performs two functions.
• Basic Validation − First of all, the form must be
checked to make sure all the mandatory fields are
filled in. It would require just a loop through each field
in the form and check for data.
• Data Format Validation − Secondly, the data that is
entered must be checked for correct form and value.
Your code must include appropriate logic to test
correctness of data.
Example:
<html>
<head>
<script language="javascript" type="text/javascript">
function validate()
{
if(form.name.value==0)
{
alert("Username should not be empty");
form.name.focus();
return false;
}
if(form.password.value==0)
{
alert("password should not be empty");
form.password.focus();
return false;
}
if(form.password.value.length<6)
{
Output:
{
alert("Address should not be empty");
form.name.focus();
return false;
}
if(form.mobile.value==0)
{
alert("Mobile num should not be empty");
form.name.focus();
return false;
}
if(form.mobile.value.length<10)
{
alert("Mobile num should be 10 digits");
form.name.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<center>
<form name="form" onsubmit="return validate(this);"
action="login.jsp">
<h1>Register Here</h1>
<table>
<tr><td>Enter Name</td><td> <input type="text"
name="name"></td></tr>
Output:
INTRODUCTION TO JQUERY:
jQuery Syntax:
EVENTS:
Event Description
<script>
$(document).ready(function()
{
$("#p1").click(function()
{
alert("You clicked on the
paragraph");
});
$("#p2").dblclick(function()
{
alert("You double clicked on the
paragraph");
});
$("#p3").hover(function()
{
alert("mouse moved over the
paragraph");
});
});
</script>
</head>
<body>
<p id="p1">Click on this paragraph</p>
<br>
<p id="p2">Double Click on this paragraph</p>
<br>
<p id="p3">Move cursor over this paragraph</p>
</body>
</html>
Output:
Keyboard events:
List of keyboard events:
1. keydown
2. keypress
3. keyup
Example:
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquer
y.min.js">
</script>
<script>
$(document).ready(function()
{
$("input").keydown(function()
{
$(this).css("background-
color","yellow");
});
$("input").keyup(function()
{
$(this).css("background-
color","pink");
});
});
</script>
</head>
<body>
<form method="post">
Enter name:<input type="text"
name="t1"><br>
</form>
</body>
</html>
Output:
Mouse events:
List of Mouse events:
1. mousedown
2. mouseenter
3. mouseleave
4. mousemove
5. mouseout
6. mouseover
7. mouseup
Example:
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquer
y.min.js">
</script>
<script>
$(document).ready(function()
{
$("#i1").mouseenter(function()
{
$("#i1").css("background-color","yellow");
});
$("#i1").mouseout(function()
{
$("#i1").css("background-color","pink");
});
$("#i2").mousedown(function()
{
$("#i2").css("background-color","blue");
});
$("#i2").mouseup(function()
{
$("#i2").css("background-color","green");
});
$("#i3").mouseover(function()
{
alert("cursor is over this heading");
});
});
</script>
</head>
<body>
<h1 id="i1">Mouse Cursor over this heading 1 to trigger mouse
events</h1>
<h1 id="i2">Mouse Cursor over this heading 2 to trigger mouse
events</h1>
<h1 id="i3">Mouse Cursor over this heading 3 to trigger mouse
events</h1>
</body>
</html>
Output:
Form events:
List of form events:
1. Submit
2. Change
3. Focus
4. Blur
Example:
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/j
query/3.4.1/jquery.min.js">
</script>
<script>
$(document).ready(function()
{
$("form").submit(function()
{
alert("Form is submitted");
});
$("input").focus(function()
{
$(this).css("background-
color","yellow");
});
$("input").blur(function()
{
$(this).css("background-
color","pink");
});
$("input").change(function()
{
alert("Text is changed");
});
$("input").select(function()
{
alert("Text is selected");
});
});
</script>
</head>
<body>
<form method="post">
Enter name:<input type="text" name="t1"><br>
Enter password:<input type="password" name="t2"><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
Output:
Document/Window Events:
List of Document/Window Events:
1. Load
2. Resize
3. Scroll
4. Unload
Example:
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/j
query/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(window).resize(function(){
alert("Window is resized");
});
});
</script>
</head>
<body>
<p>Resize Window</p>
</body>
</html>
Output:
EFFECTS:
Example:
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/3
.4.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#b1").click(function(){
$("img").hide(1000);
});
$("#b2").click(function(){
$("img").show("slow");
});
$("#b3").click(function(){
$("img").toggle("fast");
});
});
</script>
</head>
<body>
<img src="6.png">
<button id="b1"> Hide </button>
<button id="b2"> Show </button>
<button id="b3"> Toggle </button>
</body>
</html>
Output:
Fading effects:
$(selector).fadeOut(speed,callback);
• fadeToggle() – toggles between the
fadeIn() and fadeOut() methods.
▪ If the elements are faded
out, fadeToggle() will fade them in.
▪ If the elements are faded
in, fadeToggle() will fade them out.
▪ Syntax:
$(selector).fadeToggle(speed,callback);
• fadeTo() - allows fading to a given opacity (value
between 0 and 1).
81 Chapter 2 - JAVA SCRIPT,BOOTSTRAP,JQUERY
FULL STACK TECHNOLOGIES
▪ Syntax:
$(selector).fadeTo(speed,opacity,callback);
▪ Opacity: Specifies the opacity to fade to.
Must be a number between 0.00 and 1.00.
Example:
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1
/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#b1").click(function(){
$("img").fadeOut(1000);
});
$("#b2").click(function(){
$("img").fadeIn("slow");
});
$("#b3").click(function(){
$("img").fadeToggle("fast");
});
$("#b4").click(function(){
$("img").fadeTo("slow",0.3);
});
});
</script>
</head>
<body>
<img src="d1.png"><br><br>
<button id="b1"> Fade Out </button>
<button id="b2"> Fade In </button>
<button id="b3"> Fade Toggle </button>
<button id="b4"> Fade To </button>
</body>
</html>
Output:
Sliding effects:
With jQuery you can create a sliding effect on
elements. jQuery slide methods slide elements up and
down.
• slideUp() – used to slide up an element.
▪ Syntax:
$(selector).slideUp(speed,callback);
• slideDown() - used to slide down an element.
▪ Syntax:
$(selector).slideDown(speed,callback);
• slideToggle() – toggles between the slideDown() and
slideUp() methods.
▪ If the elements have been slide
down, slideToggle() will slide them up.
▪ If the elements have been slide
up, slideToggle() will slide them down.
▪ Syntax:
$(selector).slideToggle(speed,callback);
Program for sliding effects:
<html>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/j
query.min.js">
</script>
<script>
$(document).ready(function(){
$("#b1").click(function(){
$("h1").slideUp(1000);
});
$("#b2").click(function(){
$("h1").slideDown("slow");
});
$("#b3").click(function(){
$("h1").slideToggle("fast");
});
});
</script>
</head>
<body>
<h1 style="background-color:orange">Click on the button
to see sliding effect</h1>
<button id="b1"> Slide up </button>
<button id="b2"> Slide down </button>
<button id="b3"> Slide Toggle </button>
</body>
</html>
Output:
• animate()
▪ animate() method is used to create custom
animations.
▪ multiple (CSS) properties can be animated at
the same time using animate()
▪ changes an element from one state to
another with CSS styles.
▪ Syntax:
$(selector).animate({params},speed,callback);
▪ params - required parameter defines
the CSS properties to be animated.
• Stop() –
▪ The jQuery stop() method is used to stop an
animation or effect before it is finished.
▪ works for all jQuery effect functions,
including sliding, fading and custom
animations.
▪ Syntax:
$(selector).stop();
▪ kills the current animation being performed
on the selected element.
• Program for animate and stop:
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/
3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#b1").click(function(){
$("div").animate({left:'850px', height:'+=250',
width:'+=250px'},1000);
});
$("#b2").click(function(){
$("div").stop();
});
});
</script>
</head>
<body>
<button id="b1">Start Animation</button>
<button id="b2">Stop Animation</button>
<br><br>
<div style="background-
color:blue;width:300px;height:300px;position:absolu
te"></div>
</body>
</html>
Output:
BOOT STRAP:
You can:
<script src="https://maxcdn.bootstrapcdn.com/bootstr
ap/3.4.1/js/bootstrap.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
</html>
2. Bootstrap 3 is mobile-first
3. Containers
Bootstrap also requires a containing element to wrap
site contents.
There are two container classes to choose from:
1. The .container class provides a responsive fixed
width container
2. The .container-fluid class provides a full width
container, spanning the entire width of the
viewport
Grid Classes
Example:
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-8">.col-sm-8</div>
</div>
Once everything is ready, you can create the first page. This
page should provide the basic
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale =1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/
bootstrap.min.css" crossorigin="anonymous">
</head>
<body>
<h1>Hello Bootstrap 4</h1>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/
jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/
bootstrap.min.js" crossorigin="anonymous"></script>
</body>
</html>
Typography
Bootstrap's global default font-size is 14px, with a line-
height of 1.428.
This is applied to the <body> element and all
paragraphs (<p>).
• <mark>
• <abbr>
• <blockquote>
• <dl>
• <code>
• <kbd>
• <pre>
• table
• table-striped
• table-bordered
• table-hover
Forms
Forms are fully supported in Bootstrap 4. Many of the
components are mainly used to make the forms responsive and
can be used with any screen width
<form>
<div class="form-group">
<label for="txtMail">eMail</label>
<input type="email" class="form-control" id="txtMail"
placeholder="eMail">
</div>
<div class="form-group">
<label for="txtPassword">password</label>
<input type="password" class="form-control"
id="txtPassword" placeholder="Password">
</div>
<div class="form-group">
<label for="txtFile">File Selection</label>
<input type="file" id="txtFile">
<p class="form-text small">
Here is the help for uploading. </p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Save
</label>
</div>
<button type="submit" class="btn btn-secondary"> Send
</button>
</form>