WAD Notes
WAD Notes
WAD Notes
Example analogy:
HTML -> car body(only metal)
CSS -> Car paint , decoration etc.
Javascript -> car engine + internal working
Creating our first website:
We start building a website by creating a file named index.html
HTML programs should be always saved with .html extension
Comments in HTML
Comments in HTML should be used to mark text which should not be parsed
<!-- HTML comment - ->
Case sensitivity
HTML is not case sensitive language <H1> and <h1> are both same
We can add elements inside body tag to define the page layout.
<body> → opening tag
Content (text, image, audio,video etc)
</body> → closing tag
HTML attributes:
Used to add more information corresponding to an HTML tag.
Eg: <h1 align=”left” > THis is heading </h1>
We can either use single or double quotes for attribute value.
HTML Heading
A HTML heading or HTML h tag can be defined as a title or a subtitle which you want to display on
the webpage. When you place the text within the heading tags <h1>.........</h1>, it is displayed on the
browser in the bold format and size of the text depends on the number of heading.
There are six different HTML headings which are defined with the <h1> to <h6> tags, from highest
level h1 (main heading) to the least level h6 (least important heading).
Example: Output:
Note: If we are using various <p> tags in one HTML file then browser automatically adds a single blank
line between the two paragraphs.
Example:
<body>
<p>If you want to break a line <br> in a paragraph, <br> use the BR element in <br> your HTML
document. </p>
</body>
Output:
HTML <hr> tag
HTML <hr> tag is used to specify a paragraph-level thematic break in HTML document. It draw a
horizontal line between them. It is also called a Horizontal Rule in HTML.
Example:
<h2>HTML</h2>
<p>HTML is a language for describing web pages.</p>
<hr>
<h2>HR Tag </h2>
The src and alt are important attributes of HTML img tag. All attributes of HTML image tag are given
below.
1) src
It is a necessary attribute that describes the source or path of the image. It instructs the browser
where to look for the image on the server.The location of image may be on the same directory or
another server.
2) alt
The alt attribute defines an alternate text for the image, if it can't be displayed. The value of the alt
attribute describe the image in words.
3) width
It is an optional attribute which is used to specify the width to display the image.
4) height
It h3 the height of the image.
Example:
<i> used to make text italic. <i> italic text </i> italic text
<mark> This tag is used to highlight <mark> marked text marked text
text. </mark>
<u> This tag is used to underline <u> underline text underline text
text written between it. </u>
<ins> This tag displays the <ins> inserted text inserted text
content which is added </ins>
<big> This tag is used to increase <big> Big</big> Text Big Text
the font size by one
conventional unit.
<small> This tag is used to decrease <small> small small Text
</small> Text
the font size by one unit
HTML Lists
HTML Lists are used to specify lists of information. All lists may contain one or more list elements.
There are three different types of HTML lists:
Note: We can create a list inside another list, which will be termed as nested List.
example:
<ol>
<li>HTML</li>
<li>Java</li>
<li>JavaScript</li>
<li>SQL</li>
</ol>
start attribute
The start attribute is used with ol tag to specify from where to start the list items.
<ol type="1" start="5"> : It will show numeric values starting with "5".
<ol type="A" start="5"> : It will show capital alphabets starting with "E".
<ol type="a" start="5"> : It will show lower case alphabets starting with "e".
<ol type="I" start="5"> : It will show Roman upper case value starting with "V".
Example:
Output:
5. HTML
6. Java
7. JavaScript
8. SQL
reversed Attribute:
This is a Boolean attribute of HTML <ol> tag, and it is new in HTML5 version. If you use the reversed
attribute with tag then it will numbered the list in descending order (7, 6, 5, 4......1).
HTML Unordered List or Bulleted List displays elements in bulleted format . We can use unordered
list where we do not need to display items in any particular order.
● Disc
○ circle
Square
None
Example
<ul>
<li>HTML</li>
<li>Java</li>
<li>JavaScript</li>
<li>SQL</li>
</ul>
Output:
○ HTML
○ Java
○ JavaScript
○ SQL
HTML Description List or Definition List displays elements in definition form like in dictionary. The
<dl>, <dt> and <dd> tags are used to define description list.
Example:
<dl>
<dt>HTML</dt>
<dd>is a markup language</dd>
<dt>Java</dt>
<dd>is a programming language and platform</dd>
<dt>JavaScript</dt>
<dd>is a scripting language</dd>
<dt>SQL</dt>
<dd>is a query language</dd>
</dl>
Output:
HTML
is a markup language
Java
is a programming language and platform
JavaScript
is a scripting language
SQL
is a query language
Example
A simple HTML table:
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds</td>
<td>Maria</td>
<td>Germany</td>
</tr>
</table>
Output:
Tag Description
To change the space between table cells, use the CSS border-spacing property on the
table element:
Example
<table>
<tr>
<th colspan="2">Name</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
</table>
Output:
Note: The value of the colspan attribute represents the number of columns to span.
HTML Table - Rowspan
To make a cell span over multiple rows, use the rowspan attribute:
Example
<table>
<tr>
<th>Name</th>
<td>Jill</td>
</tr>
<tr>
<th rowspan="2">Phone</th>
<td>555-1234</td>
</tr>
<tr>
<td>555-8745</td>
</tr>
</table>
Output:
The value of the rowspan attribute represents the number of rows to span.
Every HTML element has a default display value, depending on what type of element it is.
The two most common display values are block and inline.
Block-level Elements
A block-level element always starts on a new line, and the browsers automatically add some
space (a margin) before and after the element. A block-level element always takes up the full
width available (stretches out to the left and right as far as it can).
HTML Forms
An HTML form is used to collect user input. The user input is most often sent to a
server for processing.
Example :
The <form> Element
The HTML <form> element is used to create an HTML form for user input:
<form>
.
form elements
.
</form>
The <form> element is a container for different types of input elements, such as: text
fields, checkboxes, radio buttons, submit buttons, etc.
● <input type="url">
● <input type="week">
<input type="image"
src="img_submit.gif" defines an image as a
alt="Submit" width="48" submit button.The path to
height="48"> the image is specified in
the src attribute.
Input Restrictions
Here is a list of some common input restrictions:
Attribute Description
checked Specifies that an input field should be pre-selected when the page
loads (for type="checkbox" or type="radio")
Example
<video width="320" height="240" controls autoplay muted >
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
How it Works
The controls attribute adds video controls, like play, pause, and volume.
It is a good idea to always include width and height attributes. If height and width are
not set, the page might flicker while the video loads.
The <source> element allows you to specify alternative video files which the browser may
choose from. The browser will use the first recognized format.
The text between the <video> and </video> tags will only be displayed in browsers that
do not support the <video> element.
Attributes of <video>
Example
<audio controls>
<source src="horse.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
How it Works
The controls attribute adds audio controls, like play, pause, and volume.
The <source> element allows you to specify alternative audio files which the browser may
choose from. The browser will use the first recognized format.
The text between the <audio> and </audio> tags will only be displayed in browsers that
do not support the <audio> element.
Attributes of <audio>
Image Maps
The HTML <map> tag defines an image map. An image map is an image with clickable
areas. The areas are defined with one or more <area> tags.
Example
<img src="workplace.jpg" alt="Workplace" usemap="#workmap">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer"
href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Coffee" href="coffee.htm">
</map>
The image is inserted using the <img> tag. The only difference from other images is that
you must add a usemap attribute
The usemap value starts with a hash tag # followed by the name of the image map, and is
used to create a relationship between the image and the image map.
The <map> element is used to create an image map, and is linked to the image by using
the required name attribute
Shape
You must define the shape of the clickable area, and you can choose one of these values:
You must also define some coordinates to be able to place the clickable area onto the
image.
What is CSS?
● CSS stands for Cascading Style Sheets
● CSS describes how HTML elements are to be displayed on screen, paper, or in other
media
● CSS saves a lot of work. It can control the layout of multiple web pages all at once
● External stylesheets are stored in CSS files
CSS Syntax
A CSS rule consists of a selector and a declaration block.
Each declaration includes a CSS property name and a value, separated by a colon.
Multiple CSS declarations are separated with semicolons, and declaration blocks are
surrounded by curly braces.
Example
p {
color: red;
text-align: center;
}
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
The id of an element is unique within a page, so the id selector is used to select one unique
element!
To select an element with a specific id, write a hash (#) character, followed by the id of the
element.
<!DOCTYPE html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
<p id="para1">Hello World!</p>
</body>
</html>
To select elements with a specific class, write a period (.) character, followed by the class
name.
<!DOCTYPE html>
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1 class="center">Red and center-aligned heading</h1>
<p class="center">Red and center-aligned paragraph.</p>
</body>
</html>
Types of CSS
There are three ways of inserting a style sheet:
● External CSS
● Internal CSS
● Inline CSS
External CSS
The external style sheet is generally used when you want to make changes on multiple pages. It is
ideal for this condition because it facilitates you to change the look of the entire web site by
changing just one file.
It uses the <link> tag on every pages and the <link> tag should be put inside the head section.
Example:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
The external style sheet may be written in any text editor but must be saved with a .css extension.
This file should not contain HTML elements.
Internal CSS
The internal style sheet is used to add a unique style for a single document. It is defined in <head>
section of the HTML page inside the <style> tag.
Example:
<!DOCTYPE html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: red;
margin-left: 80px;
}
</style>
</head>
<body>
<h1>The internal style sheet is applied on this heading.</h1>
<p>This paragraph will not be affected.</p>
</body>
</html>
Inline CSS
We can apply CSS in a single element by inline CSS technique.
The inline CSS is also a method to insert style sheets in HTML document. This method mitigates
some advantages of style sheets so it is advised to use this method sparingly.
If you want to use inline CSS, you should use the style attribute to the relevant tag.
Example
Border Properties
Font Properties
font-size Specifies the font size of text xx-small, x-small, small, medium, large, x-large,
xx-large, smaller, larger, length, %, inherit
font-style Specifies the font style for text normal, italic, oblique, inherit
Javascript
JavaScript (js) is a light-weight object-oriented programming language which is used by several
websites for scripting the webpages. It is an interpreted, full-fledged programming language that
enables dynamic interactivity on websites when applied to an HTML document.
Features of JavaScript
There are following features of JavaScript:
1. All popular web browsers support JavaScript as they provide built-in execution environments.
2. JavaScript follows the syntax and structure of the C programming language. Thus, it is a
structured programming language.
3. JavaScript is a weakly typed language, where certain types are implicitly cast (depending on
the operation).
6. It is a case-sensitive language.
JavaScript Example
<script type="text/javascript">
document.write("Hello JavaScript by JavaScript");
</script>
JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and
external JavaScript file
Link external javascript file : <script type="text/javascript" src="message.js"></script>
The text/javascript is the content type that provides information to the browser about the data.
JavaScript Comment
The JavaScript comments are meaningful way to deliver message. It is used to add information
about the code, warnings or suggestions so that end user can easily interpret the code.
The JavaScript comment is ignored by the JavaScript engine i.e. embedded in the browser.
1. Single-line Comment
It is represented by double forward slashes (//). It can be used before and after the
statement.
<script>
// It is single line comment
document.write("hello javascript");
</script>
2. Multi-line Comment
It can be used to add single as well as multi line comments. So, it is more convenient.
It is represented by forward slash with asterisk then asterisk with forward slash. For example:
<script>
JavaScript Variable
A JavaScript variable is simply a name of storage location. There are two types of variables
in JavaScript : local variable and global variable.
There are some rules while declaring a JavaScript variable (also known as identifiers).
JavaScript is a dynamic type language, means you don't need to specify type of the variable
because it is dynamically used by JavaScript engine. You need to use var here to specify the data
type. It can hold any type of values such as numbers, strings etc. For example:
JavaScript Operators
JavaScript operators are symbols that are used to perform operations on operands.
There are following types of operators in JavaScript.
1. Arithmetic Operators
+ Addition 10+20 = 30
- Subtraction 20-10 = 10
/ Division 20/10 = 2
% Modulus (Remainder) 20%10 = 0
= Assign 10+10 = 20
JavaScript If-else
The JavaScript if-else statement is used to execute the code whether condition is true or false.
There are three forms of if statement in JavaScript.
1. If Statement
2. If else statement
3. if else if statement
JavaScript If statement
It evaluates the content only if expression is true. The syntax of JavaScript if statement is given
below.
if(condition){
//content to be evaluated
Example:
<script>
var a=20;
if(a>10){
document.write("value of a is greater than 10");
}
</script>
if(condition){
//content to be evaluated if condition is true
}
else{
//content to be evaluated if condition is false
}
Example:
<script>
var a=20;
if(a%2==0){
document.write("a is even number");
}
else{
document.write("a is odd number");
}
</script>
Example:
<script>
var a=20;
if(a==10){
document.write("a is equal to 10");
}
else if(a==15){
document.write("a is equal to 15");
}
else if(a==20){
document.write("a is equal to 20");
}
else{
document.write("a is not equal to 10, 15 or 20");
}
</script>
JavaScript Switch
The JavaScript switch statement is used to execute one code from multiple expressions. It is just
like else if statement. But it is convenient than if..else..if because it can be used with numbers,
characters etc.
switch(expression){
case value1:
code to be executed;
break;
case value2:
code to be executed;
break;
......
default:
code to be executed if above values are not matched;
}
<script>
var grade='B';
switch(grade)
{
case 'A':
document.write(“A Grade”);
break;
case 'B':
document.write(“B Grade");
break;
case 'C':
document.write("C Grade");
break;
default:
document.write("No Grade");
}
</script>
JavaScript Loops
The JavaScript loops are used to iterate the piece of code using for, while, do while or for-in loops. It
makes the code compact. It is mostly used in array.
1. for loop
2. while loop
3. do-while loop
Example:
<script>
for (i=1; i<=5; i++)
{
document.write(i + "<br/>")
}
</script>
Output:
while (condition)
{
code to be executed
}
<script>
var i=11;
while (i<=15)
{
document.write(i + "<br/>");
i++;
}
</script>
3) JavaScript do while loop
The JavaScript do while loop iterates the elements for the infinite number of times like while loop.
But, code is executed at least once whether condition is true or false. The syntax of do while loop is
given below.
do{
code to be executed
}while (condition);
<script>
var i=21;
do {
document.write(i + "<br/>");
i++;
}while (i<=25);
</script>
JavaScript Functions
JavaScript functions are used to perform operations. We can call JavaScript function many times to
reuse the code.
Let’s see the simple example of function in JavaScript that does not has arguments.
<script>
function msg()
{
alert("hello! this is message");
}
</script>
<input type="button" onclick="msg()" value="call function"/>
<script>
function getcube(number)
{
alert(number*number*number);
}
</script>
<form>
<input type="button" value="click" onclick="getcube(4)"/>
</form>
<script>
function getInfo()
{
return "hello javatpoint! How r u?";
}
</script>
<script>
document.write(getInfo());
</script>
JavaScript Objects
Javascript objects can be created of two types: 1) User defined objects 2) Native objects
A javaScript object is an entity having state and behavior (properties and method). For example: car,
pen, bike, chair, glass, keyboard, monitor etc.
We already know that JavaScript variables are containers for data values.
Objects are variables too. But objects can contain many values.
This code assigns many values (Fiat, 500, white) to a variable named car:
Example
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
The name:values pairs in JavaScript objects are called properties example: age: 50
person.lastName; OR person["lastName"];
Output: Doe
Object Methods
Objects can also have methods.
Example:
Output:
2) Native objects
Array Objects
Arrays are a special type of objects. The typeof operator in JavaScript returns "object" for
arrays.
Arrays use numbers to access its "elements". In this example, person[0] returns John:
Objects use names to access its "members". In this example, person.firstName returns
John:
<script>
var emp=["Sonoo","Vimal","Ratan"];
</script>
<script>
var emp = new Array();
emp[0] = "Arun";
emp[1] = "Varun";
emp[2] = "John";
</script>
JavaScript String
String Properties
The following table lists the standard properties of the String object.
Property Description
length Returns the length of a string.
String Methods
The following table lists the standard methods of the String object.
Example:
var str = "Hello world";
var str2 = " this is string";
You can use different Date constructors to create date object. It provides methods to get and set
day, month, year, hour, minute and seconds.
1. Date()
2. Date(milliseconds)
let d = new Date(1517356800000);
document.write(d);
3. Date(dateString)
let d = new Date("31 January 2018");
document.write(d);
getDate() It returns the integer value between 1 and 31 that represents the day for the
getDay() It returns the integer value between 0 and 6 that represents the day of the
getFullYears() It returns the integer value that represents the year on the basis of local
time.
getHours() It returns the integer value between 0 and 23 that represents the hours on
getMilliseconds() It returns the integer value between 0 and 999 that represents the
getMinutes() It returns the integer value between 0 and 59 that represents the minutes
getMonth() It returns the integer value between 0 and 11 that represents the month on
getSeconds() It returns the integer value between 0 and 60 that represents the seconds
setDate() It sets the day value for the specified date on the basis of local time.
setDay() It sets the particular day of the week on the basis of local time.
setFullYears() It sets the year value for the specified date on the basis of local time.
setHours() It sets the hour value for the specified date on the basis of local time.
setMilliseconds() It sets the millisecond value for the specified date on the basis of local
time.
setMinutes() It sets the minute value for the specified date on the basis of local time.
setMonth() It sets the month value for the specified date on the basis of local time.
setSeconds() It sets the second value for the specified date on the basis of local time.
JavaScript Math
The JavaScript math object provides several constants and methods to perform mathematical
operation
Methods Description
ceil() It returns a smallest integer value, greater than or equal to the given number.
floor() It returns largest integer value, lower than or equal to the given number.
. Example:
document.write(Math.cbrt(9) + "<br>");
document.write(Math.ceil(15.453) + "<br>");
document.write(Math.exp(9) + "<br>");
document.write(Math.floor(2.456) + "<br>");
document.write(Math.hypot(45,23) + "<br>");
document.write(Math.log(9) + "<br>");
document.write(Math.max(9,8,10,5) + "<br>");
document.write(Math.min(9,8,10,5) + "<br>");
document.write(Math.pow(2,3) + "<br>");
document.write(Math.random() + "<br>");
document.write(Math.round(14.25) + "<br>");
document.write(Math.sqrt(25) + "<br>");
document.write(Math.trunc(12.563) + "<br>");
By the help of Number() constructor, you can create number object in JavaScript. For example:
If value can't be converted to number, it returns NaN(Not a Number) that can be checked by isNaN()
method.
Methods Description
toExponential() It returns the string that represents exponential notation of the given number.
toFixed() It returns the string that represents a number with exact digits after a decimal
point.
toPrecision() It returns the string representing a number of specified precision.
Example:
var no =1022;
document.write(Number.isFinite(453) + "<br>");
document.write(Number.isInteger(45.5) + "<br>");
document.write(no.toExponential() + "<br>");
document.write(no.toFixed(2) + "<br>");
document.write(no.toPrecision() + "<br>");
When html document is loaded in the browser, it becomes a document object. It is the root element
that represents the html document. It has properties and methods. By the help of document object,
we can add dynamic content to our web page.
Properties –
cookie - Returns all name/value pairs of cookies in the document
document - Mode Returns the mode used by the browser to render the
document
domain - Returns the domain name of the server that loaded the
document
lastModified - Returns the date and time the document was last
modified
readyState - Returns the (loading) status of the document
referrer Returns the URL of the document that loaded the current
document
title - Sets or returns the title of the document
URL - Returns the full URL of the document
Example:
document.writeln (document.cookie);
document.writeln(document.documentMode);
document.writeln(document.domain);
document.writeln(document.lastModified);
document.writeln(document.readystate);
document.writeln(document.referrer);
document.writeln(document.title);
document.writeln(document.URL);
Method Description
writeln("string") writes the given string on the doucment with newline character at
the end.
getElementsByTagName() returns all the elements having the given tag name.
getElementsByClassName() returns all the elements having the given class name.
Here, document is the root element that represents the html document.
Let's see the simple example of document object that prints name with welcome message.
<script type="text/javascript">
function printvalue(){
var name=document.form1.name.value;
alert("Welcome: "+name);
}
</script>
<form name="form1">
Enter Name:<input type="text" name="name"/>
<input type="button" onclick="printvalue()" value="print name"/>
</form>
Javascript - innerHTML
The innerHTML property can be used to write the dynamic html on the html document.
It is used mostly in the web pages to generate the dynamic html such as registration form,
comment form, links etc.
document.getElementById('mylocation').innerHTML=data;
}
</script>
<form name="myForm">
<input type="button" value="comment" onclick="showcommentform()">
<div id="mylocation"></div>
</form>
</body>
</html>