HTML, CSS, JavaScript, Bootstrap
HTML, CSS, JavaScript, Bootstrap
Contents
<img> ............................................................................................................................................................ 41
Hyperlinks ......................................................................................................................................... 42
<a> ................................................................................................................................................................ 42
List tags ............................................................................................................................................. 46
<ul> ............................................................................................................................................................... 46
<ol> ............................................................................................................................................................... 47
<dl> ............................................................................................................................................................... 48
Table tags .......................................................................................................................................... 49
<table> ......................................................................................................................................................... 49
<iframe> ............................................................................................................................................ 52
Entities .............................................................................................................................................. 54
<meta>............................................................................................................................................... 55
Forms ................................................................................................................................................. 56
<form> .......................................................................................................................................................... 56
<input> ......................................................................................................................................................... 57
<button> ...................................................................................................................................................... 75
<fieldset> ..................................................................................................................................................... 76
<legend> ...................................................................................................................................................... 76
<label>.......................................................................................................................................................... 77
<select> ........................................................................................................................................................ 78
<textarea> ................................................................................................................................................... 81
<div> and <span>.............................................................................................................................. 81
<div> ............................................................................................................................................................. 81
<span> .......................................................................................................................................................... 82
Advanced Tags.................................................................................................................................. 82
<hr>............................................................................................................................................................... 82
<pre> ............................................................................................................................................................ 82
<abbr> .......................................................................................................................................................... 83
<bdo> ........................................................................................................................................................... 84
<audio> ........................................................................................................................................................ 84
<video>......................................................................................................................................................... 85
<details> and <summary> .......................................................................................................................... 86
<figure> and <figcaption> ......................................................................................................................... 86
<datalist> ..................................................................................................................................................... 87
<progress> ................................................................................................................................................... 89
<meter>........................................................................................................................................................ 89
<output> ...................................................................................................................................................... 90
Fundamentals
Application
• It is a program that runs based on the operating system.
• Program is a collection of statements (instructions) to the system.
• For example, a statement instructs the computer to store a value. Another statement instructs the
computer to do addition of numbers.
• Examples: Notepad, MS Word, Google, Facebook, Flipkart etc.
Client
• It is a machine or device (desktop, laptop, tablet, phone or Smart TV), which can access the data
from server.
• The device which is used by the user is called as "client".
Browser
• It is software (tool) installed on the client, to see the output of the web page. User gives input in the
browser and gets the output in the browser.
• The browser sends a request to server to get web page.
• Browser provides navigation among web pages.
• Browser executes the html, css, javascript programs and displays corresponding output to the
user.
• Browsers are developed by different companies. For example, "Chrome" browser was developed
by "Google" company.
Important browsers:
▪ Google Chrome
▪ Mozilla Firefox
▪ Microsoft Internet Explorer
▪ Microsoft Edge
▪ Apple Safari
▪ Android Browser
▪ Opera
Web application
• It is a set of programs that are running on the browser to interact with the user.
• It is responsible to store information temporarily.
• It is responsible to interact with server i.e. sending request to server and get response from server.
Http
• Http stands for “Hypertext Transfer Protocol”.
• It is a protocol, which provides a set of rules to send request to server and get response from server.
• Http protocol defines "request format" and "response format".
• Http protocol defines HTTP status codes, Http Content Types etc.
HTML 4 & 5
Introduction to HTML
• HTML stands for “Hypertext Markup Language”.
• “Hypertext” means “the text that can be transferred from internet server to internet client”.
• HTML is a markup language. The markup language is a language, which syntax will be in the form
of tags.
• HTML is used to design web pages. That means HTML is used to create elements (such as headings,
paragraphs, icons, menus, logos, images, textboxes, buttons etc.) in the web pages.
• HTML is easy language to understand.
• HTML is “client side language”. That means the html code executes on the client (browser).
• HTML is supported by all the browsers such as Google Chrome, Mozilla Firefox, Microsoft Internet
Explorer, Safari, Opera and other browsers.
• HTML is used developed by “Tim Berners-Lee” and maintained by “W3C” (World Wide Web).
• HTML is used in all real web sites today.
• The file extension should be “.html”.
• HTML is the interpreter-based language. That means the HTML code will be converted into
machine language in line-by-line manner. Browser interprets HTML code.
• HTML is not a case sensitive language. That means you can write the html code in either upper case
or lower case.
HTML Versions
• HTML 1.0 : Nov 1991
• HTML 2.0 : Mar 1995
• HTML 3.0 : Jan 1997
• HTML 4.0 : Dec 1997
• HTML 5.0 : Oct 2014
• HTML 5.1 : Nov 2016
• HTML 5.2 : Dec 2017
Tag
• A tag is a keyword, enclosed within “<” and “>” in HTML language.
• Tag is instruction / command to browser.
• Tag is used to display some specific output in the web page.
• Syntax: <tag>
Types of tags
• Tags are two types:
1. Paired tags: Contains opening tag and ending tag. The opening tag specifies starting point of
the output. The closing tag specifies end point of the output. Ex: <h1> hello </h1>
2. Unpaired tags: Contains single tag only (no separate ending tag). Ex: <hr>
• The <html> tag represents starting and ending point of the HTML program. The <html> tag contains
two child tags, those are <head> and <body>
• The <head> tag represents non-content information of the web page. The information that doesn't
appear in the web page is called as "non-content".
• The <body> tag represents content information of the web page. The information that appears in
the web page is called as "content".
Click on “Next”.
Click on “Next”.
Click on “Next”.
Check the checkbox “Add Open with Code action to Windows Explorer file context menu”.
Check the checkbox “Add Open with Code action to Windows Explorer directory context menu”.
Click on “Next”.
Click on “Install”.
Click on “Finish”.
• Go to "c:\" and click on "New folder". Enter the new folder name as "html".
• Select “c:\html” folder and enter the filename as “first.html”.
• Click on “Save”.
• Now the html file (c:\html\first.html) is ready.
• Double click on “first.html” (or) Right click on “first.html” and click on “Open With” – “Google
Chrome”.
<head>
• <head> tag represents non content information of the page. The information that doesn't appear
in the web page is called as "non content".
Syntax:
<head> </head>
Example:
<head> </head>
<body>
• <body> tag represents content information of the page. The information that appears inside the
web page is called as "content".
Syntax:
<body> </body>
Example:
<body> </body>
<title>
• <title> tag is used to specify the title of the web page that appears in the browser’s title bar.
• <title> tag should be used in <head> tag only.
• <title> is a paired tag.
Syntax:
<title>Title here</title>
Example:
<title>My title</title>
Attributes
• Attributes are the details about the tag (command).
• Every tag has its own set of attributes.
• Attribute contains a value; The value should be written inside the double quotes.
Syntax: <tag attribute=”value”></tag>
• DOCTYPE is a directive in HTML, which tells the browser about the version of html that you are
using in the web page.
• Various versions of html have various DOCTYPE’s.
1. HTML 4
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
2. XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3. HTML 5
<!DOCTYPE html>
Headings
<h1>
• It is used to create first level heading (main heading). The headings are displayed in very large size
in the output. Every browser assigns a specific size for each level of heading. The size of heading is
decided by the browsers, not fixed.
• It is a paired tag.
Syntax:
<h1>heading here</h1>
Example:
<h1>Heading 1 here</h1>
<h2>
• It is used to create second level heading (sub heading).
• It is a paired tag.
Syntax:
<h2>heading here</h2>
Example:
<h2>Heading 2 here</h2>
<h3>
• It is used to create third level heading (sub heading).
• It is a paired tag.
Syntax:
<h3>heading here</h3>
Example:
<h3>Heading 3 here</h3>
<h4>
• It is used to create third level heading (sub heading).
• It is a paired tag.
Syntax:
<h4>heading here</h4>
Example:
<h4>Heading 4 here</h4>
<h5>
• It is used to create third level heading (sub heading).
• It is a paired tag.
Syntax:
<h5>heading here</h5>
Example:
<h5>Heading 5 here</h5>
<h6>
• It is used to create third level heading (sub heading).
• It is a paired tag.
Syntax:
<h6>heading here</h6>
Example:
<h6>Heading 6 here</h6>
Example on Headings:
Paragraphs
• <p> tag is used to create a paragraph.
• Browsers display a line break, before and after each paragraph.
• Browsers display an empty line between paragraphs.
• It is a paired tag.
Syntax:
<p>paragraph here</p>
Example:
<p>Hello</p>
Example on <p>
<br>
• It is used to moves the cursor to the next line.
• The content next to the <br> will be display in the next line.
• It is an unpaired tag.
Syntax:
<br>
Example:
<br>
Example on <br>
<b>
• It is used to display the text in bold.
• The text enclosed within the <b> tag will be display as bold.
• Use <b> tag to display important text that you want to highlight.
• It is a paired tag.
Syntax:
<b>bold text</b>
Example:
<b>Hello</b>
Example of <b>
<i>
• It is used to display the text in italic.
• The text enclosed within the <i> tag will be display as italic.
• It is a paired tag.
Syntax:
<i>italic text</i>
Example:
<i>Hello</i>
Example of <i>
<u>
• It is used to display the text in underline.
• The text enclosed within the <u> tag will be underlined.
• Use <u> tag display important text.
• It is a paired tag.
Syntax:
<u>underline text</u>
Example:
<u>Hello</u>
Example on <u>
<strike>
• It is used to display the text in strikeout.
• The <strike> tag to display un-important text.
• It is a paired tag.
Syntax:
<strike>strikeout text</strike>
Example:
<strike>Hello</strike>
Example on <strike>
<strong>
• It is used to display the text in strong.
• <strong> and <b> tags are visually same.
• The strong tag content will be pronounced "strongly" (stressfully) by the screen readers for the
blind people.
• It is a paired tag.
Syntax:
<strong>strong text</strong>
Example:
<strong>Hello</strong>
Example on <strong>
<em>
• It is used to display the text in emphasis (special status).
• <em> and <i> tags visually same.
• The strong tag content will be pronounced stylishly by the screen readers for the blind people.
• It is a paired tag.
Syntax:
<em>emphasis text</em>
Example:
<em>Hello</em>
Example on <em>
<sup>
• It is used to display the text in superscript (The text appears a bit upper side of normal line).
• Use <sup> tag to display square or cube etc.
• It is a paired tag.
Syntax:
<sup>superscript text</sup>
Example:
<sup>Hello</sup>
Example on <sup>
<sub>
• It is used to display the text in subscript (The text appears a bit bottom side of normal line).
• It is a paired tag.
Syntax:
<sub>subscript text</sub>
Example:
<sub>Hello</sub>
Example on <sub>
<img>
• It is used to display an image in the web page.
• It is strongly recommended to place the image file in the same folder, where the html file is present.
For example, if the html file is present within "c:\html" folder, we have to place the image file either
in the "c:\html" folder itself or in any subfolder of the "c:\html" folder.
• It is an unpaired tag.
Syntax:
<img src="image path here">
Example:
<img src="img1.jpg" width="200px" height="130px" title="this is tooltip">
Attributes:
1. src:
• It is used to specify path of the image file. If the image file and html file both are in
the same folder, no need to specify the full path of the image.
2. width:
• It is used to specify width (horizontal size) of the image. It represents the value in
the form of pixels. A pixel is a small "dot" (.) on the screen.
3. height
• It is used to specify height (vertical size) of the image.
4. title
• It is used to specify the tooltip (that appears when the user places mouse pointer on
the image).
5. alt
• It is used to specify the alternate text (that appears when the image is not loaded in
the browser at run time). It is strongly recommended to use "alt" for every <img>
tag in real-time, because, if the image is not loaded, at least the "alt" text appears
to the user.
Example on <img>
<a>
• It is used to create a hyperlink. When the user clicks on the hyperlink, the specified web page or
web site will be opened.
• The web basically contains links to other pages, so it is very common to use <a> tag in real-time.
• By default, every browser provides built-in style for each hyperlink, i.e. blue color + hand symbol
for mouse cursor + underline. We can customize this style by using CSS.
• It is a paired tag.
Syntax:
<a href="target url here">link text here</a>
Example:
<a href="http://www.google.com">Google</a>
Attributes:
6. href:
• It is used to specify the address of web page or web site that is to be opened when
the user clicks on the hyperlink. It can contain address of an internet web site, local
html file, local other type of file such as pdf or word document, image file etc.
7. target="_blank":
• It is used to open the target web page or web site in a separate browser tab.
Example on <a>
Page1.html
Page2.html
Example on target
Countries.html
india.html
uk.html
us.html
<ul>
• UL stands for “Un-Ordered List”.
• It is used to display the list of items with bullets.
• Inside <ul> tag, you should place one or more <li> tags.
• Use <ul> tag if you want to display any names such as person names, country names, city names
etc.
• It is a paired tag.
Syntax:
<ul>
<li>text here</li>
<li>text here</li>
…
</ul>
Example:
<ul>
<li>India</li>
<li>UK</li>
<li>US</li>
</ul>
Example on <ul>
<ol>
• OL stands for “Ordered List”.
• It is used to display the list of items with numbers.
• Inside <ol> tag, you should place one or more <li> tags.
• Use <ol> tag if you want to display names with numbers. For example, list of academic subjects (in
order).
• It is a paired tag.
Syntax:
<ol>
<li>text here</li>
<li>text here</li>
…
</ol>
Example:
<ol>
<li>India</li>
<li>UK</li>
<li>US</li>
</ol>
Example on <ol>
<dl>
• DL stands for “Definition List”.
• It is used to display a collection of definitions.
• Inside <dl> tag, you should place one or more <dt> and <dd> tags.
• It is a paired tag.
• <dt> and <dd> tags are also paired tags.
• <dt> is used to specify definition title.
• <dd> is used to specify definition data. That means it represents actual definition.
Syntax:
<dl>
<dt>title here</dt>
<dd>definition here</dd>
<dt>title here</dt>
<dd>definition here</dd>
…
</dl>
Example:
<dl>
<dt>HTML</dt>
<dd>HTML is used to design web pages.</dd>
<dt>CSS</dt>
<dd>CSS is used to apply styles.</dd>
<dt>JavaScript</dt>
<dd>JavaScript is used to create functionality.</dd>
</dl>
Example on <dl>
<table>
• <table> tag is used to display table type of data in the web page.
• A table is a collection of rows. Each row is a collection of cells.
• A table is represented as <table> tag; A row is represented as <tr>; A cell is represented as <td>.
• Inside the <table> tag, we have to use <tr>; Inside the <tr> tag, we have to use <td>.
• If the cell is representing the column heading, you can use <th> tag, instead of <td> tag.
• <caption> tag is used to specify a title for the table.
• “tr” stands for “Table row”.
• “td” stands for “Table data”.
• “th” stands for “Table header”.
• <table>, <tr>, <th>, <td> and <caption> tags are paired tags.
Syntax:
<table>
<tr>
<td>data here</td>
<td>data here</td>
…
</tr>
…
</table>
Example:
<table border="1">
<tr>
<td>One</td>
<td>Two</td>
</tr>
<tr>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<td>Five</td>
<td>Six</td>
</tr>
</table>
• <iframe> tag is used to display another web page or web site within the current web page.
• Iframe stands for “inline frame”.
• <iframe> is a paired tag.
Syntax:
<iframe src="web site address here" width="n px" height="n px">
</iframe>
Example:
<iframe src="http://www.airtel.in" width="400px" height="300px">
</iframe>
Attributes of <iframe> tag:
3. src
• “web site path”: Specifies the web site or web page path that is to be displayed in
the iframe.
4. width
• “n px”: Specifies the horizontal size of the iframe.
5. height
• “n px”: Specifies the vertical size of the iframe.
6. frameborder
• “n px”: Specifies border of the iframe.
Example on <iframe>
home.html
about.html
contact.html
• HTML Entities are pre-defined codes for displaying special symbols within the web page.
• HTML Entities are case sensitive. These must be used in lower case only.
Result Description Entity Name Entity Number
[space] non-breaking space  
< less than < <
> greater than > >
& ampersand & &
¢ cent ¢ ¢
£ pound £ £
¥ yen ¥ ¥
• <meta> tag is used to specify meta data (additional details) about the web page.
• <meta> tag provides information about the web page. Google like search engines will display your
web page in the google search results, whenever one or more keywords are matching. You must
upload your web page in the internet server to really use this.
• <meta> tag is an unpaired tag.
Example:
<meta name="keywords" content="Sony, Television, Price, Hyderabad">
<meta name="description" content="Sony LED BRAVIA Prices">
<meta name="author" content="Harsha">
<form>
• <form> tag is used to group-up the input elements; so that we can submit the entire form to the
server.
• A form is a collection of form elements such as <input>, <textarea> and <select>.
• Forms are used to collect information from the user. For example, registration for collects user
details such as username, email, password, mobile number etc.
• <form> is a paired tag.
Syntax:
<form action="server page address here" method="get">
form elements here
</form>
Example:
<form action="http://localhost/serverpage.aspx" method="get">
</form>
<input>
• <input> tag is used to create a form control (form element).
• <input> tag can create form elements such as Textbox, Checkbox, Radio button, Browser button,
submit button etc.
• <input> is an unpaired tag.
Syntax:
<input type="option here">
Example:
<input type="text">
• “submit”: Creates a submit button. Submit button is used to submit the form to the
server page. While submitting the form, all the input parameters and their values
will be sent to the server program as "query string". Ex:
?param1=value¶m2=value. The server program receives the submitted values
and do some process such as storing the data into database. For every form, it is
recommended to create a submit button. But the <input type="submit"> creates a
normal (simple submit button).
• “image”: Creates a “image submit” button. Submit button is used to submit the
form to the server page. When the user clicks on the image submit button, it also
submits the clicked position (X and Y co-ordinates) will be submitted to the server,
along with the values of other form elements.
• “button”: Creates a normal button. When the user clicks on the general button,
nothing happens by default, but you can call “JavaScript Click event” when the user
clicks on the button.
• “checkbox”: Creates a check box. Checkbox is used to display Yes/No type of
option to the user. If the checkbox is checked, it means "yes". If the checkbox is
unchecked, it means "no".
• “radio”: Creates a radio button. Radio button is used to display two or more
options to the user and allow the user to select any one of them. The “name” of radio
buttons should be same to group-up them.
• “hidden”: Creates a hidden field. Hidden field will not be appear in the web page;
but will be submitted to the server. Hidden values are useful for the programmer to
send browser / client details to server. Use hidden field when you want to submit
some fixed value to server; that you don't want to accept from the user.
• “file”: Creates a file browse button. Browse button is used for “attachment” option.
For example, you can upload image files / documents in gmail or facebook.
• “reset”: Creates a reset button. Reset button clears all fields (textboxes and others)
within the current form. The reset button must be a part of the <form> tag; then only
it can recognize the elements that are present inside the same form.
• "color": Used to create a color box, where the user can select a color.
• "date": Used to create a date box (date picker / popup calendar), where the user
can select a date.
• "time": Used to create a time box, where the user can enter a time.
• "datetime-local": Used to create a date-cum-time box, where the user can select a
date and time also.
• "month": Used to create a month box, where the user can select a month.
• "week": Used to create a week box, where the user can select a week.
• "search": Used to create a search box, where the user can enter some search text.
It also displays clear button (X) to clear the text inside the search box.
• "number": Used to create a numerical textbox, where the user can enter some
number. It either prevents typing alphabets and special symbols, or shows error
message when alphabets / special symbols are entered. Some browsers also display
increase / decrease buttons for the number textbox.
• "email": Used to create an email textbox, where the user can enter a valid email
address. It displays error message automatically, if the given email address is
invalid.
• "url": Used to create a url textbox, where the user can enter a valid website url. Ex:
http://www.google.com
2. maxlength
• Specifies the maximum no. of characters that can be typed in the textbox. By
default, the user can enter unlimited no. of characters in the textbox. Use
"Maxlength" if you want to limit to specific no. of characters./
3. readonly="readonly"
• Makes the textbox as readonly; so that the user can see the value but can’t type
anything the textbox. In the readonly textbox, the user can see, select, copy the text
value. Cursor can be placed inside the readonly textbox.
4. tabindex
• Specifies tab order. It defines tab sequence. When the user presses TAB key on the
keyboard, the cursor jumps to the next form element which is having next higher
Tabindex.
5. value
• Represents the current value of the input element. In case of checkbox and radio
button, the "value" must be set by the developer; in other type of inputs, the user
enters the value.
6. name
• Represents programmatic name of the input element that will be submitted to the
server. Based on the “name”, we can get the value of the element in the server side
program.
7. id
• Represents identification name of the input element that can be used in html, css,
and javascript to get the element programmatically.
8. src
• Used to specify the path of the image in case of <input type="image">. It by default,
refers to the same folder. It is recommended to place the image file in the same
folder, where the html file is present.
9. width
• Used to specify the width of the image in case of <input type="image">. It represents
the value in the form of pixels.
10. height
13. placeholder
o Used to display watermark text in the textbox.
o Syntax: <input type=”text” placeholder=”any text”>
14. autofocus
o Used to display the cursor directly in the specific textbox, when the web page
opened in the browser.
o Syntax: <input type=”text” autofocus=”autofocus”>
15. required
o Used to make the field (textbox) as mandatory. If the textbox is empty, it shows
error message automatically and the form will not be submitted to server.
o Syntax: <input type=”text” required=”required”>
16. pattern
o Used to apply a regular expression for the textbox for validation purpose.
o Regular expression represents “pattern” of the value.
o Ex: Alphabets only allowed, numbers only allowed etc.
o Syntax: <input type=”text” pattern=”regular expression here”>
17. min
o Specifies the minimum value.
18. max
o Specifies the maximum value.
o Applicable only for <input type=”number”>, <input type=”range”> and <input
type=”date”>.
o Syntax: <input type=”number | range | date” max=”maximum”>
19. step
o Specifies increment / decrement value for <input type=”number”>
o Syntax: <input type=”number” step=”value”>
20. novalidate
o Disables the built-in HTML 5 validations, such as required, min, max, email, date,
number etc.
o Syntax: <form novalidate=”novalidate”></form>
o Syntax: <input type=”submit” formnovalidate=”formnovalidate”>
21. formaction
o Specifies server url, to which you want to submit the form.
o Syntax: <input type=”submit” formaction=”url”>
22. formmethod
o Specifies type of submission: GET | POST
o Syntax: <input type=”submit” formmethod=”get | post”>
23. formtarget
o Opens the server page in a new browser tab, while submitting.
o Syntax: <input type=”submit” formtarget=”_target”>
24. form
o Used to make the the element as a member of the form; so that the element also
will be submitted along with other elements, while submitting the form.
o Syntax: <input type=”text” form=”id of form here”>
25. multiple
o Allows the user to select multiple files in <input type=”file”>
o Syntax: <input type=”file” multiple=”multiple”>
26. autocomplete
o Browser automatically stores the history of textbox values and display the same in
the textbox that has same name.
o The “autocomplete” attribute disables this feature.
o Syntax: <input type=”text” autocomplete=”off”>
o Syntax: <form autocomplete=”off”></form>
Example on Textboxes
Example on CheckBox
Example on readonly
Example on Maxlength
Example on Tabindex
Example on Placeholder
Example on Autofocus
Example on Required
Example on Pattern
Example on Step
Example on Novalidate
Example on Form
Example on Multiple
Example on Autocomplete
<button>
• <button> tag is used to display a submit button with image and text.
• The <button> tag is a contain, inside which you can place any content text or other html tags.
• <button> is a paired tag.
Syntax:
<button>
<img src="image file path here">
Text here
</button>
Example:
<button>
<img src="ok.png"><br>OK
</button>
<fieldset>
• <fieldset> tag is used to display a box around a set of fields.
• <fieldset> tag is a paired tag.
• Fieldset if used to group-up the set of form elements. For example, all the personal details of the
user such as Firstname, Lastname, Email, Mobile etc., can be placed inside the fieldset.
• Inside a <form> tag, we can place any no. of <fieldset> tags.
Syntax:
<fieldset>
Your textboxes here
</fieldset>
Example:
<fieldset>
<input type=”text”><br>
<input type=”text”>
</fieldset>
Example on Fieldset
<legend>
• <legend> tag is used to display a title for the fieldset.
• <legend> tag is a paired tag.
• <legend> tag can be used only inside the <fieldset>.
Syntax:
<fieldset>
<legend>title here</legend>
Your textboxes here
</fieldset>
Example:
<fieldset>
<legend>User details</legend>
<input type=”text”><br>
<input type=”text”>
</fieldset>
Example on Legend
<label>
• <label> tag is used to create field heading.
• The label provides description for the textbox, what value should be entered in the textbox.
• When the user clicks on the label, cursor will be appeared in the associated textbox automatically.
• <label> is a paired tag.
Syntax:
<label for="id of textbox here">label text here</label>
Example:
<label for="TextBox1">Username</label>
<select>
• <select> tag is used to create a dropdownlist or listbox.
• DropDownList is used to display few options to the user and allow the user to select any one of
them.
• ListBox is used to display few options to the user and allow the user to select one or more of them.
• Inside <select> tag, you should use <option> tags. Each <option> tag represents an option in the
dropdownlist.
• Optionally, <optgroup> tag can be used to group-up the <option> tags.
• <select>, <option> and <optgroup> tags are paired tags.
Syntax:
<select name="name here">
<option value="short name here">Full name here</option>
<option value="short name here">Full name here</option>
…
</select>
Example:
<select name="PaymentMode">
<option value="Select">Select</option>
<option value="DC">Debit Card</option>
<option value="CC">Credit Card</option>
<option value="NB">Net Banking</option>
</select>
Example on Dropdownlist
Example on Optgroup
Example on ListBox
<textarea>
• <textarea> tag is used to create a multi-line textbox.
• Ex: Comments, Description etc.
• <textarea> tag is a paired tag.
Syntax:
<textarea name="name here" rows="no. of rows" cols="no. of columns">
</textarea>
Example:
<textarea name="comments" rows="5" cols="25"></textarea>
Example on Textarea
<div>
• <div> is a container.
• Inside <div> tag you can place any content like normal text or any other html tags.
• When you want to divide your web page as no. of parts, each part is represented as <div> tag.
• <div> is a paired tag.
Syntax:
<div>
Your content here
</div>
Example:
<div>
Hello
</div>
<span>
• <span> represents a small amount of text, for which you can apply some special formatting.
• <span> tag doesn't provide any style by default, but we can apply style to the span tag, by using
CSS.
• <span> is a paired tag.
Syntax:
<span>Your content here</span>
Example:
<span>Hello</span>
<hr>
• It is used to display a horizontal line (horizontal ruler).
• It acts as separation between two parts of the web page
• It is an unpaired tag.
Syntax:
<hr>
Example:
<hr>
Example on <hr>
<pre>
• It is used to display the text as-it-is, along with the spaces and line breaks.
• It is a paired tag.
• Generally, <pre> tag is meant for displaying computer programs (for example, "for" loop syntax)
as-it-is.
• It is rare to use <pre> tag in real-time.
Syntax:
<pre>your text here</pre>
Example:
<pre>
one two
three four five
</pre>
Example on <pre>
<abbr>
• It is used to display full-form of a short-form when the user places mouse pointer on it.
• HTML / Browser doesn't provides any built-in abbreviations. We have to set both short form and
full form in the code itself.
• It is a paired tag.
• The "title" tag represents the tooltip (full form), which appears when the user places mouse pointer
on the content. The <title> can be applicable for any html tag (not only for <abbr> tag).
Syntax:
<abbr title="full form here">short form here</abbr>
Example:
<abbr title="as soon as possible">ASAP</abbr>
Example on <abbr>
<bdo>
• It is used to display the text in reverse (right-to-left) order.
• The default is "left-to-right" (LTR).
• The "dir" (direction) attribute decides whether the text should be "left to right" or "right to left".
• The text enclosed within the <bdo> tag will be display in the specific direction.
• It is a paired tag.
Syntax:
<bdo dir="rtl">your text here</bdo>
Example:
<bdo dir="rtl">Hai how are you</bdo>
Attributes:
1. dir:
• ltr: It displays the text in left-to-right.
• rtl: It displays the text in right-to-left.
Example on <bdo>
<audio>
• The <audio> tag plays an audio file in the web page.
• We have to maintain the audio file in the following formats, because different browsers support
different audio formats:
• .mp3 : IE, Chrome, Firefox, Safari, Opera
• .ogg : Chrome, Firefox, Opera
• The autoplay="autoplay" attribute starts playing the audio file as soon as web page is loaded in
the browser.
• The controls="controls" attribute displays audio player skin in the web page.
Syntax:
<audio autoplay=”autoplay” controls=”controls”>
<source src=”filename.mp3” type=”audio/mp3”>
Example on <audio>
<video>
• The <video> tag plays a video file in the web page.
• We have to maintain the video file in the following formats, because different browsers support
different video formats:
o .mp4 : IE, Chrome, Firefox, Safari, Opera
o .webm : Chrome, Firefox, Opera
o .ogg : Chrome, Firefox, Opera
• The autoplay="autoplay" attribute starts playing the video file as soon as web page is loaded in the
browser.
• The controls="controls" attribute displays video player skin in the web page.
Syntax:
<video autoplay=”autoplay” controls=”controls” width=”pixels” height=”pixels”>
<source src=”filename.mp4” type=”video/mp4”>
<source src=”filename.ogg” type=”video/ogg”>
<source src=”filename.webm” type=”video/webm”>
</video>
Example on <video>
Note: Copy “trailer.mp4”, “trailer.ogg” and “trailer.webm” files into current folder.
• Search engines like google can identify the image based on its description.
Syntax:
<figure>
<img src=”filename.extension”>
<figcaption>description here</figcaption>
</figure>
<datalist>
• It is used to display search suggestions in the textbox.
Syntax:
<datalist id=”id here”>
<option value=”value 1”>text</option>
<option value=”value 1”>text</option>
…
</datalist>
<input type=”text” list=”id here”>
Example on <datalist>
<progress>
• It is used to display the progress of a task.
• Ex: Downloading progress, Uploading progress.
Syntax:
<progress min=”minimum” max=”maximum”>
</progress>
Example on <progress>
<meter>
• It is used to display percentage of utilization.
• Ex: Disk usage.
Syntax:
<meter min=”minimum” max=”maximum”>
</meter>
Example on <meter>
<output>
• It is used to display the result of some calculation.
• Ex: Displaying “tax” based on “amount”.
Syntax:
<output id=”id here” >
</output>
Example on <output>
<article>
• The <article> tag represents “heading” and “one or more paragraphs”.
Syntax:
<article>
Content here
</article>
Example on <article>
Template Tags
• The following semantic tags are recommended in HTML 5.
• These are used to make the outline of the web page easy to understand.
HTML 4 HTML 5
Local Storage
• “Local Storage” is used to store some data in the browser memory permanently, until you manually
delete the data (or) clear the browser history.
• Local storage is used to store only string data.
• Local storage can store unlimited data.
• Local storage data is visible in the browser's developer tools (Inspect Element) option.
• If you clear the browser history, the local storage will be deleted.
• Ex: Google login page automatically stores your name, email and photo on successful login.
Session Storage
• “Session Storage” is used to store some data in the browser memory temporarily, until the browser
gets closed.
• Session storage also can store string data only, much like local storage.
• Session storage data is also visible in the browser's developer tools (Inspect Element option).
Ex: Facebook stores your email and password after login.
• “Geo Location” concept is used to identify the current location of the client device.
• Geo Location returns latitude, longitude values of the client device location, based on which you
can display maps, driving directions, traffic, address etc.
• “Web Workers” concept is used to execute a javascript file in background, without effecting the
actual performance of the page.
• It is mainly used to do some background process, such as uploading the file, processing some
records etc.
• The specified javascript file executes asynchronously; the code present within the javascript file
can't access the DOM; but it can use postMessage( ) function to pass value from the javascript to
regular script of the web page; then the script present within the web page can receive the value
and do some process for it.
postMessage(value);
Note: We can’t access DOM in the async javascript file. We have to use postMessage() function to pass
data from the javascript file to the web page.
script.js
• “Drag and Drop” concept allows the user to drag an element and drop into another element.
• We can drag any element and drop into another element.
• When we start dragging the source element, it executes "dragstart" event.
• When we hover on the droppable element, it executes "dragover" event.
• When we release the mouse pointer on the droppable element, it executes "drop" event.
Note: The “dragstart” event executes when the user starts dragging the draggable
element.
document.getElementById(“div2”).addEventListener(“dragover”, fun2);
function fun2(event)
{
event.preventDefault( );
}
Note: The “dragover” event executes when the user drags the draggable element and
places it on the top of droppable element.
• “Offline Apps” concept enables the browser to load the web page from the server for the first time
and store it in the browser memory; but second time onwards, it loads the page from the browser
memory directly, instead of loading it from the server.
• Advantage: The user can view the web page, even without network connection.
CACHE MANIFEST
#id
filename.jpg
filename.css
filename.js
c:\html\JavaScript.js
c:\html\sample.appcache
c:\html\index.html
Execution
• Download and install “nodejs” from “https://nodejs.org”. Click here to find steps to install NodeJS.
• Open “Command Prompt” and run the following commands:
npm install http-server -g
cd c:\html
http-server
• Browser send continuous requests to server, for every "n" seconds. Ex: 5 seconds.
• This concept is used to get continuous updated information (live information) from server.
• Ex: Cricket score board, election results, share market etc.
• The "EventSource" constructor function is used to start sending continuous requests to server.
• Every time when we get response (update) from server, the ""message" event executes for
"EventSource".
• The "server url" represents the address of server side program, to which you want to send request.
• The "event.data" property represents the actual data that is received from the browser.
c:\html\index.html
Execution:
• Download and install “nodejs” from “https://nodejs.org”. Click here to find steps to install
NodeJS.
cd c:\html
node httpserver.js
strokeStyle
It specifies color of the stroke (line).
ctx.strokeStyle = “color name”;
lineWidth
It specifies thickness of the stroke (line).
ctx.lineWidth = pixels;
strokeRect
It draws a rectangle, with a line.
ctx.strokeRect(x, y, width, height);
fillStyle
It specifies fill color.
ctx.fillStyle = “color name”;
fillRect
It draws a filled rectangle.
ctx.fillRect(x, y, width, height);
Example on Canvas
Example on SVG
1. <acronym>
o Use <abbr> tag instead.
2. <applet>
o Java applets is out-dated concept.
3. <basefont>
o Use CSS to set the default font.
4. <big>
o Use CSS to increase text size.
5. <center>
o Use CSS to set center alignment.
6. <dir>
o Use <ul> or <ol> to display list of items.
7. <font>
o Use CSS to set font.
8. <frame>
o Use <iframe>.
9. <frameset>
o Use <iframe>
10. <noframes>
o Use <iframe>
11. <strike>
o Use CSS to set strikeout.
12. <tt>
o Use CSS to change font.
13. <bgsound>
o Use <audio> tag to play audio.
14. <marquee>
o Use CSS / jQuery for animations.
15. <u>
o Use CSS to set underline.
1 <body> background, bgcolor, link, alink, vlink, text Use CSS instead.
8 <td>, <th> align, valign, bgcolor, width, height Use CSS instead.
Introduction to XHTML
• XHTML is “HTML” + “set of rules to maintain good quality and standards” in the html code.
• XHTML is the strict and cleaner version of HTML, recommended by W3C (World Wide Web
Consortium).
• XHTML was released in 2000.
• In realtime, XHTML is recommended.
XHTML Rules
1. <!DOCTYPE> is must.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
That means the html file has the content of “text/html” type; and the character encoding format is
“UTF” (Unicode Transformation Format), which supports all worldwide language characters.
10. Attribute minification not allowed. We must write both attribute and value.
Ex: readonly=”readonly”
11. The following tags are only allowed in <body> tag directly. All other tags must be used only inside
any of the following tags.
o <p>
o <table>
o <div>
o <ul>
o <ol>
o <h1> to <h6>
XHTML - Example
xhtml.html
CSS 2 & 3
Introduction to CSS
• CSS stands for “Cascading Style Sheet”.
• CSS is a “styling language”, which is used to apply styles to the html elements in the web page.
• CSS styles include with backgrounds, colors, margins, borders, paddings, alignments etc.
• A CSS style can overlap other CSS style; that's why it is called as "cascading" style sheets.
Syntax of CSS:
1. Tag Selector
• The “tag selector” selects all the instances of specific tag.
• Use tag selector to select multiple elemens.
Syntax: tagname
Example: p
2. ID Selector
• The “id selector” selects a single tag, based on the “id”.
• “ID” is the “identification name”; it must be unique.
• Use ID selector to select a exact single element.
• "#" is the symbol of "ID".
Syntax: #id
Example: #p1
Example on ID Selector
CSS - Properties
• “Properties” are “details” or “settings” of html tag.
• Every property contains a value.
color
• This property specifies text color (font color) of the element.
• You can specify any color of your choice.
Syntax: color: colorname;
Example: color: green;
background-color
• This property specifies background color of the element.
• You can set any color as background color.
Syntax: background-color: colorname;
Types of colors
• Colors can be represented in 3 formats.
1. Named colors
2. RGB
3. Hexadecimal number
1. Named colors:
▪ We can write name of the color directly.
▪ These are limited.
▪ We can’t get exact shade of the color.
▪ Ex: white, black, red, green, orange, pink etc.
▪ It is not recommended in real-time.
2. RGB:
▪ RGB formula specifies that the composition of 3 basic colors (red, green, blue), generates 16
million colors.
3. Hexadecimal format:
▪ “Hexadecimal format” is the shortcut for “RGB”.
▪ Hexadecimal number system supports 16 symbols as 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f.
▪ Hexadecimal number should be 6 symbols long, with “#” prefix. First two symbols represent
red; Second two symbols represent green; Third two symbols represent blue.
▪ Syntax: #redgreenblue
▪ Example:
▪ #ffffff = white
▪ #000000 = black
▪ #ff0000 = red
▪ “Hexadecimal format” is recommended in realtime.
RGB - Example
font-family
• This property specifies name of the font. You refer the font family names from notepad.
• It is recommended to specify multiple font family names; if specified browser tries the subsequent
font if the previous font is not found / not supported in the browser.
Syntax: font-family: “fontname”;
Example: font-family: “Arial”;
font-size
• This property specifies size of the font.
• You can specify the font size in the form of pixels / percentage / "EM" size.
Syntax: font-size: pixels;
Example: font-size: 30px;
font-weight
• This property applies bold.
• The default value is "normal".
• If the value is "normal", the text appears normally.
• If the value is "bold", the text appears thick (bold).
Syntax: font-weight: normal | bold;
Example: font-weight: bold;
font-style
• This property applies italic.
• The default value is "normal".
• If the value is "normal", the text appears normally.
• If the value is "italic", the text appears italic.
Syntax: font-style: normal | italic;
Example: font-style: italic;
letter-spacing
• This property specifies gap between letters. For example, in "ABC", the letter-spacing specifies gap
between "A" and "B"; and also gap between "B" and "C".
Syntax: letter-spacing: pixels;
Example: letter-spacing: 10px;
word-spacing
• This property specifies gap between words.
• Words are identified with spaces. Space is the separator of words.
Syntax: word-spacing: pixels;
Example: word-spacing: 10px;
line-height
• This property specifies height of the line of text.
• You can specify the value in the form of pixels or percentage.
Syntax: line-height: pixels;
Example: line-height: 10px;
text-decoration
• This property specifies underline / overline / strikeout for the text.
• The default value is "none".
Syntax: text-decoration: none | underline | overline | line-through;
Example: text-decoration: underline;
text-transform
• This property specifies uppercase / lowercase / title case for the text.
• The default value is "none".
• If the value is "none", the text appears normally.
• If the value is "uppercase", the text appears UPPER CASE.
• If the value is "lowercase", the text appears lower case.
• If the value is "capitalize", the first letter of each word will be Capital.
Syntax: text-transform: none | uppercase | lowercase | capitalize;
Example: text-transform: underline;
text-align
• This property specifies alignment for the text.
• The default value is "left".
Syntax: text-align: left | right | center | justify;
Example: text-align: left;
text-indent
• This property specifies left margin for the first line of the paragraph.
• It is rare to use in real-time.
• Use text-indent if you want to start first line of the paragraph from right side.
Syntax: text-indent: pixels;
Example: text-indent: 10px;
• <span> represents a small amount of text, for which you can apply some special formatting.
• <span> is a paired tag.
• <span> tag doesn't apply any style by default; but we can apply any style for it.
Syntax:
<span>Your content here</span>
Example:
<span>Hello</span>
Example of span
background-image
• This property specifies background image of the element.
• It is recommended to place the background image file in the current folder.
Syntax: background-image: url(“filename.extension”);
Example: background-image: url(“sample.png”);
background-repeat
• This property specifies repeat mode of the background image.
• The default value is "repeat".
• If the value is "repeat", the background image repeats horizontally and vertically within the image.
• If the value is "no-repeat", the background image will not be repeated; will be displayed only once
at top left corner.
background-position
• This property specifies position of the background image.
• The default value is "top left".
Syntax: background-position: top left | top center | top right |
center left | center center | center right | bottom left |
bottom center | bottom right;
Example: background-position: top center;
• The “background-position” property will be useful only when “background-repeat” is set to “no-
repeat”.
background-attachment
• This property specifies whether the background image should be scrolled along with the text, when
the user uses the scrollbars of the web page.
• If the value is "scroll", the background image will be scrolled along with the text.
• If the value is "fixed", the background image will not be scrolled along with the text; Only the text
will be scrolled; background image will be constantly appears.
Syntax: background-attachment: scroll | fixed;
Example: background-attachment: scroll;
list-style-image
• This property specifies bullet image file path for the list.
• It is recommended to place the image file in the same folder, where the html file is present.
Syntax: list-style-image: url(“filename.extension”);
Example: list-style-image: url(“tick.gif”);
• <div> is a block level element. That means it occupies 100% of the width, by default. So the content
next to the <div> tag, appears in the next line.
• Syntax: <div> any content </div>
• Example: <div> Hello </div>
“height” property
• This property specifies vertical size of the element.
• You can specify the value in the form of pixels or percentages.
Syntax: height: pixels;
Example: height: 100px;
float
• This property displays the elements side-by-side.
• If the value is "left", the elements will be displayed side-by-side, starting from "left", towards
"right".
• If the value is "right", the elements will be displayed side-by-side, staring from "right", towards
"left".
Syntax: float: left | right;
Example: float: left;
clear
• This property cancels the effect of “float” and push the current element to next line.
• It stops the sequence of “float”.
• Top stop “float:left” sequence, we use “clear:left”.
• Top stop “float:right” sequence, we use “clear:right”.
Syntax: clear: left | right;
Example: clear: left;
• "Solid" is recommended.
• Depending on the requirement, you can use any of the other borders.
Syntax: border-style: none | solid | dotted | dashed | double | inset | outset | ridge | groove;
Example: border-style: solid;
“border-width” property
• This property specifies thickness of the border.
“border-color” property
• This property specifies color of the border.
border - shortcut
• This property specifies border width, border style and border color, at-a-time, in shortcut way.
Syntax: border: borderwidth borderstyle borderColor;
Example: border: 5px solid red;
border - sides
“border-top” property
• This property specifies border width, border style and border color for top side only.
Syntax: border-top: borderwidth borderstyle bordercolor;
Example: border-top: 5px solid red;
“border-right” property
• This property specifies border width, border style and border color for right side only.
Syntax: border-right: borderwidth borderstyle bordercolor;
Example: border-right: 5px solid red;
“border-bottom” property
• This property specifies border width, border style and border color for bottom side only.
Syntax: border-bottom: borderwidth borderstyle bordercolor;
Example: border-bottom: 5px solid red;
“border-left” property
• This property specifies border width, border style and border color for left side only.
Syntax: border-left: borderwidth borderstyle bordercolor;
Example: border-left: 5px solid red;
margin
• This property specifies the margin (gap) between element to element, surrounding the element.
• For example, if two <div> tags are display side-by-side, the gap between them is called as "margin".
margin - sides
“margin-top” property
• This property specifies the top margin (gap) between element to element.
Syntax: margin-top: pixels;
Example: margin-top: 10px;
“margin-right” property
• This property specifies the right margin (gap) between element to element.
Syntax: margin-right: pixels;
Example: margin-right: 10px;
“margin-bottom” property
• This property specifies the bottom margin (gap) between element to element.
Syntax: margin-bottom: pixels;
Example: margin-bottom: 10px;
“margin-left” property
• This property specifies the left margin (gap) between element to element.
Syntax: margin-left: pixels;
margin - shortcut
• This property specifies the margin (gap) between element to element, all sides independently at-a-
time.
Syntax: margin: topmargin rightmargin bottommargin leftmargin;
Example: margin: 10px 5px 15px 30px;
padding
• This property specifies the padding (gap) between border and content of the element.
padding - sides
“padding-top” property
• This property specifies the top padding.
Syntax: padding-top: pixels;
Example: padding-top: 10px;
“padding-right” property
• This property specifies the right padding.
Syntax: padding-right: pixels;
Example: padding-right: 10px;
“padding-bottom” property
• This property specifies the bottom padding.
Syntax: padding-bottom: pixels;
Example: padding-bottom: 10px;
“padding-left” property
• This property specifies the left padding.
Syntax: padding-left: pixels;
Example: padding-left: 10px;
padding - shortcut
“padding” property - shortcut
• This property specifies the padding for all sides independently at-a-time.
Syntax: padding: toppadding rightpadding bottompadding leftpadding;
Example: padding: 10px 5px 15px 30px;
“opacity” property
• This property makes the element transparent (background information is visible through the
element).
• You can specify any number between 0 to 1.
• Any middle number between 0 and 1 is recommended. For example, "0.6".
Syntax: opacity: 0 to 1;
Example: opacity: 0.6;
1 : fully visible
0.9, …, 0.1 : transparent
0 : fully transparent / invisible
display
• This property specifies display mode of the element.
Syntax: display: block | inline | none;
Example: display: none;
• “display: none” hides the element and its space will be reclaimed by other elements automatically.
visibility
• This property specifies whether the element is visible or invisible in the web page.
Syntax: visibility: visible | hidden;
Example: visibility: hidden;
• “visibility: visible” shows the element.
• “visibility: visible” hides the element and its space will be reserved as-it-is.
overflow
• This property specifies how the text should be appear, which is outside the boundaries of the
element.
Syntax: overflow: visible | hidden | auto;
Example: overflow: auto;
• “overflow: visible” shows the additional content outside the element, which doesn’t fit within the
element.
• “overflow: hidden” hides the additional content, which doesn’t fit within the element.
position: static
• The block level elements appear line-by-line; inline elements appear side-by-side.
• It is the default.
Example of “position:static”
position: absolute
• It displays the element exactly in the specified position.
• It requires “left” and “top” properties.
Syntax: position: absolute; left: x: top: y;
Example: position: absolute; left:50px; top:50px;
Example of “position:absolute”
z-index
• This property specifies the display order (front / back side) of the element. If the z-index value is
higher, it appears to the front to the user. If the z-index value is lower, it appears at backside to the
user.
Syntax: z-index: n;
Example: z-index: 1;
Example of “z-index”
position: relative
• It also displays the element based on “x” and “y” co-ordinates (just like absolute).
• Absolute: x and y co-ordinates will be calculated from the browser.
• Relative: x and y co-ordinates will be calculated from the previous element.
Syntax: position: relative; left: x: top: y;
Example: position: relative; left: 50px; top: 50px;
Example of “position:relative”
position: fixed
• It is same as “absolute”. That means the “x” and “y” co-ordinates will be calculated from the
browser.
• When we scroll the web page, the fixed element will not be scrolled; appears in the fixed position.
Syntax: position: fixed; left: x: top: y;
Example: position: fixed; left: 50px; top: 50px;
Example of “position:fixed”
Page1.html
Page2.html
Syntax:
<tag style=”property:value; property:value; …”>
</tag>
• First we have to select the element / elements, and then only we can apply some styles to it.
• “Selector” is a “syntax to select”. It is used to select the desired elements in the web page.
• When we use a selector, the browser searches the entire web page for the matching elements and
returns the matching elements; and we apply styles only for those matching elements.
• List of CSS Selectors
1. Tag Selector
2. ID Selector
3. Class Selector
4. Compound Selector
5. Grouping Selector
6. Child Selector
7. Direct Child Selector
8. Adjacent Siblings Selector
9. Adjacent One Sibling Selector
10. Attribute Selector
11. Hover Selector
12. Focus Selector
13. Universal Selector
14. First-Child Selector
15. Last-Child Selector
16. Nth-Child Selector
17. Nth-Child Even Selector
18. Nth-Child Odd Selector
19. Before Selector
20. After Selector
21. Selection Selector
Tag Selector
• It selects all the instances of the specified tag.
• You can specify any tag name.
Syntax: tag
Example: p
ID Selector
• It selects a single instance of the tag, based on the id.
• “ID” is “identification name”.
• “ID” should be unique (can’t be duplicate) in the web page.
• # is symbol of ID selector.
Syntax: #id
Example: #p1
Example on ID Selector
Class Selector
• It selects one or more elements, based on the class name.
• We use same class for similar elements.
• "." is the symbol of class selector.
Syntax: .class
Example: .c1
Compound Selector
• It selects the instances of specific tag, which have specified class.
Syntax: tag.class
Example: p.c1
Grouping Selector
• It selects the specified group of tags.
• "," is the symbol of grouping selector.
Syntax: tag1,tag2,tag3,…
Example: div,p,h2
Child Selector
• It selects all the child tags (including grand children) of the specified parent tag.
• "space" is the symbol of child selector.
Syntax: parenttag childtag
Example: div p
Attribute Selector
• It selects all the tags that are having specified attribute.
• "[ ]" are the symbols of attribute selector.
• We can use any attribute of any html tag.
Syntax: tag[attribute=”value”]
Example: img[width=”120px”]
Hover Selector
• It applies the style only when the user places the mouse pointer on the element, at run time.
• It automatically removes the style, if the mouse pointer is moved outside the element.
• It is also called as “pseudo class”. Whenever the selector starts with “:”, it is called as “pseudo class”.
• Pseudo = unrealistic
Syntax: tag:hover
Example: p:hover
Focus Selector
• It applies the style only when the focus (cursor) is inside the element.
• It automatically removes the style when the cursor gets out of the element.
• It is also called as “pseudo class”.
Syntax: tag:focus
Example: input:focus
Universal Selector
• It selects all the tags in the web page (including <html>, <head>, <body> etc.).
• It is used to apply global styles.
Syntax: *
Example: *
First-child selector
• It selects the child tag, which is the first child of its parent tag.
• It is also called as “pseudo class”.
Note: Index starts from “1”.
Syntax: childtag:first-child
Example: p:first-child
Last-child selector
• It selects the child tag, which is the last child of its parent tag.
• It is also called as “pseudo class”.
Note: Index starts from “1”.
Syntax: childtag:last-child
Example: p:last-child
Nth-child selector
• It selects the child tag, which is the nth child tag of its parent tag.
Note: Index starts from “1”.
Syntax: childtag:nth-child(n)
Example: p:nth-child(2)
Nth-child(even) selector
• It selects all the even child tags. Ex: 2, 4, 6, …
Note: Index starts from “1”.
Syntax: childtag:nth-child(even)
Example: p:nth-child(even)
Nth-child(odd) selector
• It selects all the odd child tags. Ex: 1, 3, 5, …
Note: Index starts from “1”.
Syntax: childtag:nth-child(odd)
Example: p:nth-child(odd)
Before selector
• It inserts an image before (at left side of) the current element.
• It is also called as “pseudo element”.
Syntax: tag::before
Example: h1::before
After selector
• It inserts an image after (at right side of) the current element.
Selection selector
• It applies the style for the selected text of the web page.
• It is also called as “pseudo element”.
• "moz" stands for "Mozilla Firefox".
Syntax for Mozilla Firefox: ::-moz-selection
Syntax for Other Browsers: ::selection
Example on !important:
Table Styles
Hyperlink Styles
• It is used to apply styles to hyperlinks.
a:link: Applies styles to unvisited hyperlinks.
Menubar
• Menubar is a collection of hyperlinks arranged vertically / horizontally.
Header
• Header is the top content of the web page, which includes website logo, website name, main
options for navigation.
Resize
• It is used to make an html element, resizable in the browser.
• Syntax: resize: horizontal | vertical | both;
• Example: resize: both;
Example on Resize
Word Wrap
• It is used to split the long words into next line.
• Syntax: word-wrap: break-word;
• Example: word-wrap: break-word;
RGBA
• It is used to apply transparency to the background color only, instead of applying transparency for
the content.
• Syntax: rgba(red, green, blue, alpha)
Red = 0 to 255
Green = 0 to 255
Blue = 0 to 255
Alpha = 0 to 1
Example on RGBA
Border Radius
• It is used to apply rounded corners for any html element.
• Syntax: border-radius: pixels;
• Example: border-radius: 10px;
Shadow
Box-Shadow
• It is used to apply shadow for the element.
• Syntax: box-shadow: HorizontalPosition VerticalPosition BlurRadius Spread
ShadowColor;
• Example: box-shadow: 5px 5px 5px 2px red;
Text-Shadow
• It is used to apply shadow for the text of the element.
Example on Shadow
Multiple Columns
• It is used to divide the text of the element into multiple columns.
• Set no. of columns:
column-count: no. of columns;
-moz-column-count: no. of columns;
-webkit-column-count: no. of columns;
Transitions
• Transition is a process of changing a CSS property’s value gradually, based on the specified no.
of seconds.
• Transitions support only pixels based color based properties. Ex: width, height, opacity, font-
size, border-width, background-color, color, border-color etc.
• Syntax:
selector
{
property: startvalue;
transition: property seconds;
}
selector:hover
{
property: endvalue;
}
Example:
Transformations
• Transformations are used to display the element in a different visual dimension.
• Types of transformations:
1. Rotate Transformation
2. Skew Transformation
3. Scale Transformation
4. Translate Transformation
1. Rotate Transformation
• It is used to rotate the element, based on the specifies no. of degrees. Ex: 45deg.
Syntax: transform: rotate(degrees);
2. Skew Transformation
• It wrists the element.
Syntax: transform: skew(degrees);
Example: transform: skew(30deg);
3. Scale Transformation
• It shows the element in large size / small size, visually.
Syntax: transform: scale(number);
Example: transform: scale(2);
1 = 100% size
2 = 200% size
0.5 = 50% size
1.5 = 150% size
…
4. Translate Transformation
• It changes the visual position of the element.
Syntax: transform: translate(x, y);
Example: transform: translate(30px, 30px);
Multiple Transformations
• We can apply more than one transformation at-a-time.
Syntax: transform: rotate(degrees) scale(n) translate(x, y) skew(degrees);
Example: transform: rotate(40deg) scale(1.5) translate(30px, 30px) skew(20deg);
transform-origin
• This property specifies the fixed point for rotate transformation and sale transformation etc.
• Syntax: transform-origin: top left | top center | top right | center left |
center center | center right | bottom left | bottom center | bottom right;
• Example: transform-origin: top left;
Animations
• Animations are “group of transitions”, which will be performed one after another.
• Transition contains two points only (starting point + ending point).
• Animation contains multiple points of milestones.
• Syntax:
selector
{
animation: animationname seconds;
}
@keyframes animationname
{
0% { property:value; property:value; … },
25% { property:value; property:value; … },
50% { property:value; property:value; … },
75% { property:value; property:value; … },
100% { property:value; property:value; … }
}
Example:
Example on Animations
▪ fontname.woff
▪ fontname.css
▪ filename.html
c:\css\Stylesheet.css
c:\css\Fontexample.html
about.html
contact.html
StyleSheet.css
• “Responsive Web Design” (RWD) is used to make the web page automatically fit based on the
current device resolution.
• We divide the devices into 4 types, based on the browser width:
1. Large devices: 1200px to unlimited
2. Medium devices: 1024px to 1199px
3. Small devices: 768px to 1023px
4. Extra Small devices: 300px to 767px
Media Queries
• We use “Media Queries” to create responsive web design. The media queries apply the styles based
on the specified resolution.
1. Large devices (1200px to unlimited):
@media (min-width: 1200px)
{
}
StyleSheet.css
Bootstrap
Introduction to Bootstrap
• “Bootstrap” is a “CSS framework”, developed by “Twitter” company, which is a collection of ready-
made “css classes”, which can be used in web pages to apply styles to the elements easily.
• Bootstrap can be used without css knowledge also. To customize the bootstrap styles, CSS
knowledge is required.
• Bootstrap provides responsive web design by default.
• Bootstrap was developed based on “jQuery” and "Popper".
• jQuery is a JavaScript library, which provides a set of functions to perform DOM manipulations
easily.
• Popper is a JavaScript library, which provides a set of functions to display popup messages.
Downloading jQuery
• Go to “http://jquery.com”.
• Click on “Download jQuery 3.3.1” (version number may vary).
• Click on “Download the uncompressed, development jQuery 3.3.1”.
• If required, press "Ctrl+S" to save the file. You will get a file “jquery-3.3.1.js”.
• Copy and paste “jquery-3.3.1.js” file from Downloaded location into “c:\bootstrap” folder.
Downloading Popper
• Go to “https://unpkg.com/popper.js”.
• If required, press "Ctrl+S" to save the file. You will get a file “popper.js”.
• Copy and paste “popper.js” file from Downloaded location into “c:\bootstrap” folder.
Importing Bootstrap
Importing Bootstrap
• The "viewport meta tag" is used to set the actual width of the device as width of the web page.
• It is must to make the web page responsive.
• It also sets the initial zoom to "1" (actual size).
“container” class
• It acts as “outer container” for the entire page.
• It makes the web page responsive.
• The entire content of the page should be inside the “container”.
• It provides margin left and margin right for the page.
Syntax:
<div class=”container”>
any content
</div>
Example on Container
“container-fluid” class
• It also acts as “outer container” for the entire page.
• It also makes the web page responsive.
Syntax:
<div class=”container”>
any content
</div>
Example on Container-Fluid
Text Colors
• It is used to set colors of the text.
• Based on the requirement, the developer can use any of the available colors.
List of Classes
• text-primary
• text-success
• text-info
• text-warning
• text-danger
• text-muted
• text-secondary
• text-dark
• text-light
Background Colors
• It is used to set background colors of the element.
• Based on the requirement, the developer can use any of the available colors.
• If you want other color, you can use CSS.
List of Classes
• bg-primary
• bg-success
• bg-info
• bg-warning
• bg-danger
• bg-secondary
• bg-dark
• bg-light
Display Headings
• It is used to display headings with thin text and larger font size.
List of Classes
• display-1
• display-2
• display-3
• display-4
Text Alignment
• We can apply text alignment, by using the following bootstrap css classes.
• Default is "left alignment".
List of Classes
• text-left
• text-center
• text-right
• text-justify
Text Styles
• The following set of bootstrap classes are used to set text styles such as bold, italic, uppercase etc.
List of Classes
• font-weight-bold
• font-weight-light
• font-italic
• text-lowercase
• text-uppercase
• text-capitalize
Lead
• It is used to display a leading paragraph (in larger font size and more line height).
List of Classes
• lead
Example on Lead
Visibility
• It is used to show / hide the element in the web page.
List of Classes
• visible
• invisible
Example on Visibility
List of Classes
• .col-n
Types of Devices
Extra Small Devices:
• Very-Low-range Phones: Screens less than 1px to 575px width.
• Ex: iPhone 2G, 3G (320px width / 480px height)
<div class=”col -n”>…</div>
<div class=”col -n”>…</div>
…
Small Devices:
• Low-range phones & Tablets: Screens less than 576px to 767px width.
• Ex: iPhone 4, 4s (640px width / 960px height)
• Ex: iPhone 5, 5s, 5C, SE (640px width / 1136px height)
• Ex: iPhone 6, 6s, 7, 8 (750px width / 1334px height)
<div class=”col-sm-n”>…</div>
<div class=”col-sm-n”>…</div>
…
Medium Devices:
• Lower-mid range phones & Small laptops: Screens less than 768px to 991px width.
• Ex: Samsung Note 1 (800px width / 1280px height)
<div class=”col-md-n”>…</div>
<div class=”col-md-n”>…</div>
…
Large Devices:
• Mid-range phones & Small laptops: Screens less than 992px to 1199px width.
• Ex: iPhone 6 Plus (1080px width / 1920px height)
• Ex: iPhone 10 (1125px width / 2436px height)
<div class=”col-lg-n”>…</div>
<div class=”col-lg-n”>…</div>
…
Jumbotron
• It is used to display heading and paragraph in large size with a special box to highlight its content.
List of Classes
• jumbotron
Example on Jumbotron
Image Shapes
• It is used to display images with rounded corners.
List of Classes
• rounded
• rounded-circle
• img-thumbnail
Image Alignment
• It is used to display horizontal alignment of the image.
List of Classes
• float-left
• float-right
• mx-auto
• d-block
Image Fluid
• It is used to display reduce the size of the image automatically, if the page width is reduced.
List of Classes
• img-fluid
Basic Table
• It is used to display table with expand width and padding, horizontal borders.
List of Classes
• table
Borderless Table
• It is used to display table without borders.
List of Classes
• table-borderless
Bordered Table
• It is used to display table with both horizontal & vertical borders.
List of Classes
• table-bordered
Striped Table
• It is used to display table with alternate row background
List of Classes
• table-striped
Hover Table
• It is used to display table with background color change on row hover.
List of Classes
• table-hover
List of Classes
• table-primary
• table-success
• table-danger
• table-info
• table-warning
• table-warning
• table-active
• table-secondary
• table-light
• table-dark
List of Classes
• thead-dark
• thead-light
Table Small
• It is used to display table with small size (less padding).
List of Classes
• table-sm
Table Responsive
• It is used to display scrollbar for the table automatically, when the web page is resized.
• This class can be applicable only for <div> tag that contains <table> tag.
List of Classes
• table-responsive
Alerts
• It is used to display alert message (short message) at the top of the web page.
List of Classes
• alert
• fade
• show
• close
• alert-primary
• alert-success
• alert-info
• alert-warning
• alert-danger
• alert-secondary
• alert-light
• alert-dark
Example on Alerts
Button Colors
• It is used to display buttons with different colors.
List of Classes
• btn
• btn-primary
• btn-secondary
• btn-success
• btn-info
• btn-warning
• btn-danger
• btn-dark
• btn-light
• btn-link
Button Outline
• It is used to display buttons with only border (white background).
List of Classes
• btn-outline-primary
• btn-outline-secondary
• btn-outline-success
• btn-outline-info
• btn-outline-warning
• btn-outline-danger
• btn-outline-dark
• btn-outline-light
Button Sizes
• It is used to display large / small buttons.
List of Classes
• btn-block
• btn-lg
• btn-sm
Button Groups
• It is used to display grouped buttons.
• It reduces margin between buttons.
List of Classes
• btn-group
List of Classes
• btn-group-vertical
Button DropDown
• It is used to display dropdownlist for the button.
List of Classes
• dropdown-toggle
• dropdown-toggle-split
• caret
• dropdown-menu
• dropdown-item
Basic Badges
• It is used to indication near heading / button.
List of Classes
• badge
Example on Badges
Badge Colors
• It is used to set background colors for the badges
List of Classes
• badge
• badge-primary
• badge-secondary
• badge-success
• badge-info
• badge-warning
• badge-danger
• badge-dark
• badge-light
Pill Badges
• It is used to display more rounded badges.
List of Classes
• badge-pill
List of Classes
• progress
• progress-bar
• mx-auto
List of Classes
• bg-success
• bg-info
• bg-warning
• bg-danger
• bg-secondary
• bg-light
• bg-dark
• progress-bar-striped
• progress-bar-animated
Basic Pagination
• It is used to display page numbers.
List of Classes
• pagination
• page-item
• page-link
• active
Pagination Size
• It is used to display pagination in large / small size.
List of Classes
• pagination-lg
• pagination-sm
Pagination Alignment
• It is used to display pagination left / center / right side of the page.
List of Classes
• justify-content-center
• justify-content-end
Breadcrumbs
• It is used to display location (navigation path) of the current web page in the website.
List of Classes
• breadcrumb
• breadcrumb-item
• active
Example on Breadcrumbs
List of Classes
• list-group
• list-group-flush
• list-group-item
• list-group-item-action
List of Classes
• list-group-item-success
• list-group-item-secondary
• list-group-item-info
• list-group-item-warning
• list-group-item-danger
• list-group-item-dark
• list-group-item-light
Basic Cards
• It is used to display some content (box) with header and footer.
List of Classes
• card
• card-header
• card-body
• card-footer
Card Colors
• It is used to display some content (box) with header and footer.
List of Classes
• bg-primary
• bg-success
• bg-info
• bg-warning
• bg-danger
• bg-secondary
• bg-dark
• bg-danger
Card Images
• It is used to display cards with images.
List of Classes
• card-img-top
• card-title
• card-text
Card Groups
• It is used to display group of cards side by side.
List of Classes
• card-group
Tooltip
• It is used to display tooltip message when the user places mouse pointer on it.
List of Classes
• data-toggle="tooltip"
• data-placement="top | bottom | left | right"
• title
Example on Tooltip
Popover
• It is used to display message (some text) when the user clicks an element.
• The popover can show when the cursor focuses the element.
• The popover can have title and content also.
List of Classes
• data-toggle="popover"
• title
• data-content="some text"
• data-placement="top | bottom | left | right"
• data-trigger="focus"
Example on Popover
Basic Collapsible
• It is used to display expandable / collapsible content.
• The content will be shown when the user clicks on the button / link.
List of Classes
• collapse
• data-toggle="collapse"
• data-target="#id"
Link Collapsible
• It is used to display expandable / collapsible content, based on the link.
• The content will be shown when the user clicks on the link.
List of Classes
• show
Accordion
• It is used to display a group of collapsible items and show any one of them, when the user clicks it.
• Out of few collapsible items, only one is visible to the user.
List of Classes
• show
Example on Accordion
Inline Form
• It is used to create a simple form (with limited no. of elements), where the elements appear side-
by-side.
List of Classes
• form-inline
• form-group
• form-control
• mr-n
• form-check
• form-check-label
• form-check-input
Stacked Form
• It is used to create a form, where the form elements appear line-by-line.
List of Classes
• form-text
• form-control-file
Form Grid
• It is used to create a form, where the desired form elements appear side-by-side.
List of Classes
• form-row
List of Classes
• form-row
• col-sm-n
• col-form-label
• offset-sm-n
Input Groups
• It is used to create a form element, with some text inside it.
List of Classes
• input-group
• input-group-prepend
• input-group-append
• input-group-text
Form Validation
• It is used to display success message / error message, based on the value that is entered by the
user.
List of Classes
• needs-validation
• novalidate="novalidate"
• valid-feedback
• invalid-feedback
• valid-tooltip
• invalid-tooltip
• required="required"
• pattern="reg exp"
Basic Navigation
• It is used to display a simple navigation bar with few hyperlinks
• When the user clicks on any hyperlink, the corresponding web page (html file) will be opened.
List of Classes
• nav
• nav-item
• nav-link
Navigation Alignment
• It is used to set alignment for the simple navigation bar.
• Default is left alignment.
• You can set center / right alignment.
List of Classes
• justify-content-center
• justify-content-end
Vertical Navigation
• It is used to display the simple navigation bar in vertical mode.
List of Classes
• flex-column
Tabs
• It is used to display a set of tabs and show the corresponding content below, when the user clicks
on any one tab.
List of Classes
• nav-tabs
• data-toggle="tab"
• tab-content
• tab-pane
• container
• active
• fade
Example on Tabs
Pills
• It is used to display a set of tabs with more rounded corners and background color.
List of Classes
• nav-pills
• data-toggle="pill"
Example on Pills
List of Classes
• dropdown
• dropdown-toggle
• data-toggle="dropdown"
• dropdown-menu
• dropdown-item
Example on DropDown
List of Classes
• navbar
• navbar-expand-sm
• navbar-dark
• navbar-nav
• nav-item
• nav-link
• active
home.html
about.html
contact.html
NavBar Collapsible
• It is used to display a collapsible navbar. That means when the web page has been opened in small
devices, the menu will be automatically converted into "=" icon. When the user clicks on this icon,
the menu gets opened.
List of Classes
• navbar-expand-sm
• navbar-brand
• navbar-toggler
• data-toggle="collapse"
• data-target="#id"
• collapse
• navbar-collapse
NavBar DropDown
• It is used to display a dropdown menu for the navigation bar item.
List of Classes
• dropdown
• dropdown-toggle
• data-toggle="dropdown"
• dropdown-menu
• dropdown-item
NavBar Search
• It is used to display a search box for the navigation bar.
List of Classes
• form-inline
• form-control
• mr-sm-n
NavBar FixedTop
• It is used to display a navbar always at the top of the page, even though the user has scrolled the
page up / down.
List of Classes
• fixed-top
List of Classes
• sticky-top
Scrollspy
• It is used to change the "active" class to the current menu item, when the web page is scrolled
vertically.
List of Classes
• data-spy="scroll"
• data-target=".navbar"
• data-offset="pixels"
Example on ScrollSpy
Carousel
• It is used to display image slide show with / without text.
List of Classes
• carousel
• slide
• data-ride="carousel"
• data-interval="milli seconds"
• carousel-indicators
• data-target="#id"
• data-slide-to="n"
• active
• carousel-inner
• carousel-item
• carousel-caption
• carousel-control-prev
• carousel-control-prev-icon
• data-slide="prev"
• data-slide="next"
Example on Carousel
Modal
• It is used to display modal popup box with desired content.
List of Classes
• data-toggle="modal"
• data-target="#id"
• modal
• fade
• modal-dialog
• modal-lg
• modal-dialog-centered
• modal-content
• modal-header
• modal-body
• modal-footer
• close
• data-dismiss="modal"
Example on Modal
LESS
Introduction to LESS
• LESS stands for "LEAN CSS".
• "LESS" makes it easy to modify the CSS file. If you make the change in one place, the same will be
automatically effected in multiple places.
• The LESS code is written in ".less" files and will be converted into "css" files, as the browser
supports only CSS, but not LESS.
• If you modify the the LESS file and compile it into CSS file, the change will be effected in multiple
places in CSS.
• Additionally, LESS supports some additional features such as variables, operators, mixins, color
functions etc., which are not supported by CSS. LESS is the superset of CSS, which supports all
concepts of CSS along with the specified additional features.
• Click on "Download".
• You will get a file called "WinLess-1.9.1.msi".
• Check the checkbox "I accept the terms in the License Agreement".
• Click on "Install".
• Click on "Finish".
• WinLess opened.
• It shows the list of LESS files automatically. It also generates CSS filename automatically.
• Click on "Compile".
Output:
Variables
• In LESS, variables are used to store a value.
• The variable create once, can be used many times within the same less file. While converting into
CSS, the variables will be replaced with actual value.
• Variable names must be started with "@".
Mixins
• Mixins are used to mix a CSS class with another style.
property2: value;
}
selector
{
.classname;
property3: value;
property3: value;
}
Example on Mixins
c:\ui\StyleSheet.less
c:\ui\Page1.html
c:\ui\Page1.html
Nested Rules
• These are used to apply CSS styles for the child elements of a specific parent tag.
{
styles here
}
}
parenttag child2
{
}
c:\ui\Page1.html
Operators
• In LESS, we can use all the arithmetical operators such as +, -, *, / etc.
• The LESS compiler calculates the operators and generates the result.
Example on Operators
c:\ui\StyleSheet.less
c:\ui\Page1.html
Color Functions
• These are used to make the color darker / lighter.
Example on Operators
c:\ui\StyleSheet.less
c:\ui\Page1.html
JavaScript 5, 6 & 7
Introduction to JavaScript
• JavaScript is a programming language, which is used to create functionality in the web page.
Functionality means, “receiving inputs from the user and providing output to the user”.
• It can perform tasks such as calculations, decision making, repetitive tasks, dynamically displaying
the output, reading inputs from the user dynamically, updating content on the web page based on
the inputs, interacting with server, validations etc.
• It’s operators and control statements are similar to “C” language.
• JavaScript is client-side (browser-side) language. That means it executes on the browser. It can also
be used in server by using NodeJS.
• JavaScript is a case sensitive language.
• JavaScript is “interpreter-based” language. That means the code will be converted into machine
language, line-by-line.
• JavaScript was developed by “Netscape Corporation” in 1996.
• JavaScript is the implementation of "EcmaScript". "EcmaScript" is the specification of "JavaScript".
• "EcmaScript" is designed by "Ecma International".
Syntax of JavaScript
• Note: You can write the <script> tag either in <head> tag or <body> tag also; however, writing
<script> tag at the end of <body> tag is a best practice.
• The type="text/javascript" attribute specifies that you are using javascript language; It is optional.
console.log()
• The console.log() statement is used to display value in the browser console.
• To see console, first run the program in the browser and press "F12" or right click and choose
"Inspect Element" – "Console" option in the browser.
Syntax: console.log(value);
Click on “Next”.
Click on “Next”.
Click on “Next”.
Check the checkbox “Add Open with Code action to Windows Explorer file context menu”.
Check the checkbox “Add Open with Code action to Windows Explorer directory context menu”.
Click on “Next”.
Click on “Install”.
Click on “Finish”.
• Go to "c:\" and click on "New folder". Enter the new folder name as "ui".
• Select “c:\ui” folder and enter the filename as “first.html”.
• Click on “Save”.
• Now the typescript file (c:\ui\first.html) is ready.
• Double click on “first.html” (or) Right click on “first.html” and click on “Open With” – “Mozilla
Firefox” / "Open With" – "Google Chrome".
• In the browser, right click in the web page and click on "Inspect Element" (or) press "F12" function
key to open console.
• Variable is a “named memory location” in RAM, to store a value temporarily, while executing the
program.
• In JavaScript, the variables will be persisted (stored), while the web page is running in the browser.
• The value of variable can be changed any no. of times during the web page execution.
• The data type of the variable can be changed any no. of times during the web page execution, in
JavaScript.
Example on Variables
Arithmetical Operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder
Assignment Operators
= Assigns to
+= Add and assigns to
-= Subtract and assigns to
*= Multiply and assigns to
/= Divide and assigns to
%= Remainder and assigns to
Relational Operators
== Equal to
!= Not Equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
Logical Operators
&& And (both conditions should be true)
|| Or (At least any one condition should be true)
! Not (given condition will be reverse)
Concatenation Operator
+ Attaches two strings and returns a single string.
Ex: “new” + “delhi” = “newdelhi”
• Control statements are used to control (change) the program execution flow.
• These are used to make the execution flow jump forward / jump backward.
• JavaScript supports two types of control statements:
1. Conditional Control Statements: Used to jump forward.
2. Looping Control Statements: Used to jump backward.
if
• “If” statement is used to check a condition, and execute the code only if the condition is TRUE.
• Types of “if”
1. If
2. If-else
3. Else-if
4. Nested if
Simple If
If Else
Example of “if-else”
Else if
Example of “else-if”
Nested If
Switch-case
• It is used to check a variable’s value, whether it matches with any one of the set of cases, and execute
the code of the matched case.
• Syntax:
Example on Switch-case
While
• “While” statement is used to execute the code repeatedly, while the condition is TRUE.
Example on While
Do-While
• “Do-while” loop is mostly same as “while” loop.
• The difference is: “while” loop checks the condition for the first time also; but “do-while” loop
doesn’t check the condition for the first time.
Example on Do-While
For
• “For” loop is mostly same as “while” loop.
• The difference is: “While” loop has the initialization, condition and iteration in three different places,
so that it will be difficult to understand, if the code increases. But “for” loop has the initialization,
condition and iteration in the same line, so that it will be easy to understand.
Example on For
• Function is a re-usable “block” of the program, which is a set of statements with a name.
• The large program can be divided into many parts; each individual part is called as “function”.
• Functions are re-usable. That means functions can be called anywhere and any no. of times within
the program. Every time when we call the function, the execution flow jumps to the function
definition; executes the function and comes back to the calling portion.
Parameters: The values that are passed from “calling portion” to the “function definition” are called as
“arguments” and “parameters”.
Return: The value that is passed from “function definition” to the “calling portion” is called as “return”.
Note: Every function has a property called "arguments", which represents the list of arguments that
are passed to the function. arguments = { 0: argument1, 1: argument1, … }
Arguments - Example
Recursion
• Recursion is a technique of calling a function inside itself.
• Whenever a function calls itself, it is said to be "recursion".
• We should check the condition inside the function and call the same function, only if the condition
is TRUE.
Example: Factorial of number = n * n-1 * n-2 * n-3 … * 0
Factorial of 5 = 5 * 4 * 3 * 2 * 1 = 120
Syntax:
function functionname()
{
samefunctionname();
}
Recursion - Example
Example on Arrays
Example on Push
Example on Splice
Example on Insert
Introduction to Objects
• Object Oriented Programming (OOP) is a programming paradigm (programming style), which is
based on the concept of “objects”.
• Object represents a physical item / entity.
• Object is a collection of two types of members:
1. Properties / Fields
2. Methods
• Properties / Fields: Details about the object. Properties are the variables stored inside the object.
Properties are used to store data about specific person, product or thing.
• Methods: Manipulations on the properties. Methods are the functions stored inside the object.
Functions read values from properties and/or write values into properties.
Example:
“Car” object
- Properties
▪ carModel: Honda City
▪ carColor: Black
▪ colorNo: 1234
- Methods
▪ start( )
▪ changeGear( )
▪ stop( )
• In the above example, the "Car" object has three properties called "carModel", "carColor",
"colorNo", which have respective values. The
Creating Objects
• We can create object in 2 ways:
1. Object Literals
2. Constructor Function
Object Literals
• Object literals are represented as curly braces { }, which can include properties and methods.
• The property and value are separated with : symbol.
• Syntax: { “property”: value, “method”: function( ) { … } }
Constructor Function
• Constructor function is a function that receives an empty (new) object, initializes properties and
methods to the object.
• The "this" keyword inside the constructor function represents the current working object. For
example, if it is called for the first time, the "this" keyword represents the first object; if it is called
second time, the "this" keyword represents the second object.
• The constructor function can receive one or more parameters and initializes the same values into
the respective properties.
• The "reference variable" stores the reference (address) of the object and used to access its members
(properties and methods), outside the object literal / constructor function.
Object.Keys
• The “Object.keys” method is used to retrieve the list of properties of an object as an array.
• Sometimes, you will get data from server / browser storage. Then you don't know what properties /
methods are present inside the object. Then you have to use Object.keys() are used to properties /
methods of the object and also read its values programmatically.
Syntax: Object.keys(reference variable);
Example: Object.keys(stu);
• This is useful if you don’t know what properties are exist in the object.
Example on Object.Keys
JSON
• "JSON" stands for "JavaScript Object Notation".
• JSON is similar to "Object Literal", but having the following differences.
▪ In "Object Literal", double quotes are optional for the properties; In "JSON", double quotes are must
for properties.
▪ In "Object Literal", methods are allowed; In "JSON", methods are not allowed.
• JSON is mainly used as data exchange format; it can be transferred from browser to server; and vice
versa; and also it is can be stored in the local storage and session storage.
Syntax:
{ "property" : value, "property" : value, … }
Stringify
• The “JSON.stringify” is used to convert “Object Literal” to “JSON” format. JSON is a text format
which follows “JavaScript Object Literal” syntax. JSON is mainly used for store or exchange data
between browser and server.
Syntax: JSON.stringify(reference variable)
Example: JSON.stringify(stu)
Example on JSON.stringify
Parse
• The “JSON.parse” is used to convert “JSON” to “Object Literal” format.
Syntax: JSON.parse(json data)
Example: JSON.parse(‘ { “a”:10, “b”: 20 } ’)
Example on JSON.parse
Object Array
• “Object Array Literal” is a collection of “objects created using constructor function”, stored as an
array.
Syntax:
[
new constructorfunction(argument1, argument2, …),
new constructorfunction(argument1, argument2, …),
new constructorfunction(argument1, argument2, …),
…
]
Prototype
• The "prototype" generally represents model of the object, which contains list of properties and
methods of the object.
Example on Prototype
Inheritance
• The process of creating an object based on another object is called as “inheritance”.
• So all the properties and methods of the parent object is inherited into the child object.
Syntax:
function parentconstructorfunction(arguments)
{
…
}
function childconstructorfunction(arguments)
{
parentconstructorfunction.call(this, arguments);
…
}
Example on Inheritance
• "Data type" specifies type of data that you want to store in the variable or property.
• JavaScript supports the following data types:
1. number : Any numbers
2. string : Collection of characters
3. Boolean : true, false
4. undefined : undefined
5. object : { }, new
6. function : function() { }
String
• “String” is a collection of characters. The characters include with the following:
1. Uppercase alphabets : A-Z
2. Lowercase alphabets : a-z
3. Digits : 0-9
4. Symbols : $ # @ & * etc.
5. Spaces
• JavaScript string literals should be in either single quotes or double quotes.
Ex: ‘hello123’
“hello123”
typeof
• The "typeof" keyword is used to get the data type of given value.
Syntax: typeof value
Example: typeof 10
Example on typeof
undefined vs null
• "undefined" represents "empty value", which is by default to assigned to every uninitialized
variables. The developer is not supposed to assign "undefined" manually.
• "null" represents "empty value", which can be assigned by the developer.
• The datatype of "undefined" is "undefined".
• The datatype of "null" is "object".
Syntax of undefined: undefined
Syntax of null: null
== and ===
• == operator checks only value; === operator checks value and data type also.
• == operator internally first converts the right side value in the data type of left side and checks the
value. === operator will not perform any automatic conversion and directly checks the value.
• Use == operator to check only value. Use === operator check value and data type
Syntax of ==: value1 == value2
Syntax of ===: value1 === value2
Example on == vs ===
String Function
• The "String()" is a pre-defined function, which is used to convert a number into string.
Syntax: String(number value)
ToString Function
• The "toString()" is a pre-defined function, which is used to convert a number into string.
• The difference between String() and toString() function is:
• The String() function is a global function; The toString() function is available inside number data
type.
Syntax: numbervalue.toString()
Number Function
• The "Number()" is a pre-defined function, which is used to convert string to number.
• It returns "NaN", if the string is alphanumerical / alphabetic. "Nan" stands for "Not A Number",
which indicates the value is not a number. The datatype of "NaN" is "number".
• It returns "0", if the string is empty / space.
Syntax: Number(string value)
ParseInt Function
• The "parseInt()" is a pre-defined function, which is used to convert string to number.
• parseInt() doesn't supports decimal places.
ParseFloat Function
• The "parseFloat()" is a pre-defined function, which is used to convert string to number.
• It is same as parseInt(); but it accepts decimal places.
• It returns number, if the string is alphanumerical that starts with number.
• It returns "NaN", if the string is alphanumerical that starts with alphabet.
• It returns "NaN", if the string is alphabetic.
• It returns "Nan", if the string is empty / space.
Syntax: parseFloat(string value)
+ Unary Operator
• It is same as "Number()" function, but it supports only numbers.
Syntax: +
toFixed() function
• It converts the number into string and adds the specified no. of decimal places.
• It also rounds the number.
Syntax: numbervalue.toFixed(no. of decimals)
Example on toFixed()
toUpperCase( )
• This function converts the string value into uppercase and returns it.
Syntax: string.toUpperCase( )
Example: “hello”.toUpperCase( ) → “HELLO”
Example toUpperCase()
toLowerCase( )
• This function converts the string value into lowercase and returns it.
Syntax: string.toLowerCase( )
Example: “HELLO”.toLowerCase( ) → “hello”
Example on toLowerCase()
length
• This property returns the no. of characters in the string.
Syntax: string.length
Example: “hello”.length →5
Example on length
charAt( )
• This function returns the single character present at the specified index.
• Index starts from 0 (zero).
Syntax: string.charAt( )
Example: “hello”.charAt(1) →e
Example on charAt()
charCodeAt( )
• This function returns the ASCII value of the single character present at the specified index.
Syntax: string.charCodeAt( )
Example: “hello”.charCodeAt(1) → 101
Example on charCodeAt()
substr( )
• This function returns a part of the string, starting from specified index, upto the specified length of
the string.
Syntax: string.substr(index, length)
Example: “hyderabad”.substr(2, 4) → dera
Example on substr()
indexOf( )
• This function searches for the given sub string in the string, and returns the index of the first
character in the given string if it is found; it returns -1, if the character is not found.
• In case if you specify the start index, searching starts from the specified startindex.
Syntax: string.indexOf(“character”, startindex)
Example: “hyderabad”.indexOf(“a”) →5
Example: “hyderabad”.indexOf(“era”) →3
Example: “hyderabad”.indexOf(“z”) → -1
• This function always considers the first occurrence only.
Example on indexOf()
replace( )
• It replaces a “word” with “another word”.
Syntax: string.replace(“old word”, “new word”)
Example: “MS Office”.replace(“Office”, “Windows”) → MS Windows
Example on replace()
split( )
• This function converts a string into an array of many small strings and returns the array, based on
the separator character.
Syntax: string.split(“separator character”)
Example: “how are you”.split(“”) → [ “how”, “are”, “you” ]
Example on split()
trim( )
• This function removes the unnecessary spaces at left side and right side of the string.
Syntax: string.trim( )
Example: “ abc def ”.trim( ) → “abc def”
Example on trim()
concat( )
• This function attaches two strings and make then as a sinle string.
Syntax: string.concat( “another string” )
Example: “united”.concat(“states”) → “unitedstates”
Example on concat()
new Date( )
• This is used to get the current system date and time.
Syntax: new Date( )
Example: new Date( ) → Thu Aug 10 2017 11:04:51 GMT+0530 (India Standard Time)
toLocaleDateString( )
• This function returns the date in the following format: M/d/yyyy
Syntax: new Date( ).toLocaleDateString( )
Example: new Date( ).toLocaleDateString( ) → 8/10/2017
Example on toLocaleDateString()
toLocaleTimeString( )
• This function returns the time in the following format: hh:mi:ss am/pm
Syntax: new Date( ).toLocaleTimeString( )
Example: new Date( ).toLocaleTimeString( ) → 11:04:51 AM
Example on toLocaleTimeString()
getTime( )
• This function returns the no. of milli seconds since “1/1/1970 12:00:00 AM”.
Syntax: new Date( ).getTime( )
Example: new Date( ).getTime( ) → 1502343291481
Example on getTime()
getDay( )
• This function returns the no. of the day of the week.
0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
Syntax: new Date( ).getDay( )
Example: new Date( ).getDay( ) →4
Example on getDay()
getDate( )
• This function returns only the date.
Example on getDate()
getMonth( )
• This function returns only the month (0 to 11).
Syntax: new Date( ).getMonth( )
Example: new Date( ).getMonth( ) →7
Example on getMonth()
getFullYear( )
• This function returns only the year.
Syntax: new Date( ).getFullYear( )
Example: new Date( ).getFullYear( ) → 2017
Example on getFullYear()
getHours( )
• This function returns only the hours (in 24 hours format).
Syntax: new Date( ).getHours( )
Example: new Date( ).getHours( ) → 11
Example on getHours()
getMinutes( )
• This function returns only the minutes.
Syntax: new Date( ).getMinutes( )
Example: new Date( ).getMinutes( ) →4
Example on getMinutes()
getSeconds( )
• This function returns only the seconds.
Syntax: new Date( ).getSeconds( )
Example: new Date( ).getSeconds( ) → 51
Example on getSeconds()
getMilliseconds( )
• This function returns only the milli seconds.
Syntax: new Date( ).getMiliseconds( )
Example: new Date( ).getMilliseconds( ) → 481
Example on getMilliseconds()
NoScript
• It is used to display a message to the user, when the user has disabled JavaScript in the browser.
Syntax:
<noscript>message</noscript>
Examples on NoScript
Clousers
• “Clousers” are used to create private variables that are accessible to only a set of methods.
• Create a function; Create private variables in the same function with "var" keyword; Return an
object from this function; If you call the function, the private variables of this function are not
accessible outside the function.
Syntax:
var functionname = function( )
{
var variablename = value;
return
{
method: function( )
{
code
},
method: function( )
{
code
}
};
};
Examples on Clousers
Hoisting
• JavaScript automatically lifts-up the variable declarations (that are created using "var" keyword)
to top of the program or top of the function. This is called as “Hoisting”.
Note: Variable declarations cum initializations are not lifted-up.
Example on Hoisting
• DOM (Document Object Model) is the tree structure of html elements (tags) that are present within
the web page.
• When the web page has been opened in the browser, DOM will be automatically created by the
browser.
• The changes made to DOM are called as “DOM manipulations”. DOM manipulations are performed
using JavaScript.
• The entire browser window is called as "window". The webpage running on the browser is called as
"document". It has only one main element called <html>. It has two children <head> and <body>.
There are many children for both <head> and <body>.
Example:
1. location.href
2. navigator.userAgent
3. screen
4. screen
5. alert()
6. confirm()
7. print()
8. setTimeout()
9. setInterval()
10. scrollTo
11. open()
1. location.href
• This property represents url of the current web page running in the browser window.
• Syntax: window.location.href
2. navigator.userAgent
• This property represents the name of current browser.
• Syntax: window.navigator.userAgent
3. navigator.screenX
• This property represents X value of current browser position on the screen.
• Syntax: window.navigator.screenX
4. navigator.screenY
• This property represents Y value of current browser position on the screen.
• Syntax: window.navigator.screenY
5. alert()
• This method displays an information dialogbox (message dialogbox) to the user.
• It contains only OK button.
Syntax: window.alert("message")
Example: window.alert("Hello");
Example on alert()
6. confirm()
• This method displays an confirmation dialogbox to the user.
• It contains OK and Cancel buttons.
• It returns "true", if the user clicks on "OK" button; It returns "false", if the user clicks on "Cancel"
button.
Syntax: window.confirm("message")
Example on confirm()
7. print()
• This method displays print dialogbox, which is used to print the current webpage through selected
printer.
• In Google Chrome, it shows "Print Preview" also.
Syntax: window.print()
Example on print()
8. setTimeout()
• This method calls the specified function, after completion of specified no. of milli seconds.
• Note: 1000 milli seconds = 1 second
Syntax: window.setTimeout(function, milli seconds)
Example on setTimeout()
9. setInterval()
• This method calls the specified function repeatedly, for every completion of specified no. of milli
seconds.
• Note: 1000 milli seconds = 1 second
Syntax: window.setInterval(function, milli seconds)
Example on setInterval()
10. scrollTo()
• This method scrolls the web page horizontally / vertically to the specified X and Y co-ordinates.
• The X and Y co-ordinates are calculated in the form of pixels.
Syntax: window.scrollTo(x, y)
Example on scrollTo()
11. open()
• This method opens a browser child window / popup window.
• It is mainly useful for opening ads.
Syntax: window.open("url", "logical name", "width=pixels, height=pixels");
Example on open()
open.html
mypage.html
1. title
• This property represents title of the web page.
• Syntax: document.title
2. head
• This property represents <head> tag of the web page.
Syntax: document.head
3. body
• This property represents <body> of the web page.
Syntax: document.body
4. images
• This property represents all images of the web page, as an array.
Syntax: document.images
5. links
• This property represents all hyperlinks (<a> tags) of the web page, as an array.
Syntax: document.links
6. URL
• This property represents url of the web page.
Syntax: document.URL
document.write()
• This method displays the given message in the web page.
Syntax: document.write("message")
Example on document.write()
document.getElementById()
• This method retrieves the single element that has specified ID.
Syntax: document.getElementById("id")
Example on document.getElementById()
document.getElementsByName()
• This method retrieves the array of elements that have specified name.
Syntax: document.getElementsByName("name")
Example on document.getElementsByName()
document.getElementsByTagName()
• This method retrieves the array of elements that have specified tag name.
Syntax: document.getElementsByTagName("tag name")
Example on document.getElementsByTagName()
document.getElementsByClassName()
• This method retrieves the array of elements that have specified class name.
Syntax: document.getElementsByClassName("class name")
Example on document.getElementsByClassName()
document.querySelectorAll()
• This method retrieves the array of elements that are matching with specified selector.
• You can use any CSS selectors:
1. Tag Selector : tag
2. ID Selector : #id
3. Class Selector : .classname
4. Grouping Selector : tag1,tag2,…
5. Child Selector : parent child
Syntax: document.querySelectorAll("selector")
Example on document.querySelectorAll()
document.querySelector()
• This method retrieves the first element that matches with specified selector.
Syntax: document.querySelector("selector")
Example on document.querySelector()
tagName
• This property represents name of the tag.
• Syntax: document.getElementById("id").tagName
Example on tagName
id
• This property represents id of the tag.
Syntax: document.getElementById("id").id
Example on id
innerHTML
• This property represents content of the tag.
Syntax: document.getElementById("id").innerHTML
Example on innerHTML
innerText
• This property represents content of the tag, without tags.
Syntax: document.getElementById("id").innerText
Example on innerText
style
• This property represents css style of the tag.
Syntax: document.getElementById("id").style.property
Example on style
parentElement
• This property represents parent element of the tag.
• Syntax: document.getElementById("id").parentElement
Example on parentElement
children
• This property represents child elements of the tag.
Syntax: document.getElementById("id").children
Example on children
scrollTop
• This property moves vertical scrollbar, based on the specified no. of pixels.
Syntax: document.getElementById("id").scrollTop
Example on scrollTop
setAttribute()
• This method sets an attribute to the tag.
Syntax: document.getElementById("id").setAttribute("attribute name", "value")
Example on setAttribute()
getAttribute()
• This method gets the value of specified attribute of the tag.
• Syntax: document.getElementById("id").getAttribute("attribute name")
Example on getAttribute()
removeAttribute()
• This method removes the specified attribute of the tag.
Syntax: document.getElementById("id").removeAttribute("attribute name")
Example on removeAttribute()
attributes
• This property retrieves all the attributes of the tag, along with values.
Syntax: document.getElementById("id").attributes
Example on attributes
hasAttribute()
• This method checks whether the element has specified attribute or not; returns "true" if it contains;
returns "false" if it doesn't contain.
Syntax: document.getElementById("id").hasAttribute("attribute name");
Example on hasAttribute()
focus()
• This method places the cursor inside the element.
Syntax: document.getElementById("id").focus()
Example on focus()
click()
• This method clicks the specified element (equal to manual mouse click).
• Syntax: document.getElementById("id").click()
Example on click()
remove()
• This method removes the current element.
Syntax: document.getElementById("id").remove()
Example on remove()
document.createElement()
• This method creates a new element for the specified tag.
Syntax: document.createElement("tag name")
appendChild()
• This method adds new child element to the current element.
Syntax: document.appendChild(newelement)
Example on appendChild()
• “Event” is a keyboard / mouse action, that is performed by the user, at run time.
• “Event Handling” is a concept of attaching the event with a function.
• Whenever the user performs an action, automatically the element raises the event; then we can
call a function.
List of Events
1. click
2. dblclick
3. mouseover
4. mouseout
5. mousemove
6. keyup
7. keypress
8. focus
9. blur
10. change
11. contextmenu
12. cut
13. copy
14. paste
“Click” event
• The “click” event executes when the user clicks on the element.
Syntax:
addEventListener(“click”, functionname);
function functionname( )
{
}
“Dblclick” event
• The “dblclick” event executes when the user double clicks on the element.
Syntax:
addEventListener(“dblclick”, functionname);
function functionname( )
{
}
“Mouseout” event
• The “mouseout” event executes when the user moves the mouse pointer from inside to outside the
element.
• Syntax:
addEventListener(“mouseout”, functionname);
function functionname( )
{
}
“Mousemove” event
• The “mousemove” event executes when the user moves the mouse pointer across the element.
Syntax:
addEventListener(“mousemove”, functionname);
function functionname( )
{
}
event
Represents the information, given by the browser. Whenever the user performs an action, the browser
collects some information, and it passes the same information to the function automatically. This is
called “event”.
event.pageX: Represents “X” co-ordinate of mouse pointer position.
“Keyup” event
• The “keyup” event executes when the user presses any key on the keyboard, while the cursor is inside
the element.
Syntax:
addEventListener(“keyup”, functionname);
function functionname( )
{
“Keypress” event
• The “keypress” event executes when the user presses any key on the keyboard, while the cursor is
inside the element.
• “Keypress” event is very similar to “keyup” event.
• When you press any key on the keyboard, the following process happens:
1. “Keypress” event executes.
2. The character will be added in the textbox.
3. “Keyup” event executes.
• “Keypress” event executes before accepting the currently pressed character into the element.
“Keyup” event executes after accepting the currently pressed character into the element.
• In “keypress” event, we can accept / reject the currently pressed character, because it executes
“before accepting” the character.
• In “keyup” event, we can’t reject the currently pressed character, because it executes “after
accepting” the character.
Syntax:
addEventListener(“keypress”, functionname);
function functionname( )
{
}
• event.which: Represents the ASCII value of currently pressed character. That means when the user
presses a character, the browser automatically identifies its ASCII value and passes the same to the
function, as “event.which”.
• ASCII = American Standard Code for Information Interchange
• As per ASCII, every character has a number.
▪ 65 to 90 : A-Z
▪ 97 to 122 : a-z
▪ 48 to 57 : 0-9
▪ 32 : Space
▪8 : Backspace
▪9 : TAB
▪ 13 : Enter
• event.preventDefault( ): It stops the default functionality. That means it rejects the currently
pressed character. If this method is not used, by default it accepts the currently pressed character.
“Blur” event
• The “blur” event executes when the cursor goes out of the element.
• Syntax:
addEventListener(“blur”, functionname);
function functionname( )
{
}
“Change” event
• The “change” event executes when the value of the element has been changed.
• That means it executes in following cases:
1. When the user modifies the value of textbox and presses TAB key.
2. When the user checks / unchecks the checkbox.
3. When the user selects the radio button.
4. When the user selects an item in the dropdownlist.
Syntax:
addEventListener(“change”, functionname);
function functionname( )
{
“Contextmenu” event
• The “contextmenu” event executes when the user right clicks on an element.
Syntax:
addEventListener(“contextmenu”, functionname);
function functionname( )
{
}
“Cut” event
• The “cut” event executes when the user selects “cut” option with keyboard / mouse.
Syntax:
addEventListener(“cut”, functionname);
function functionname( )
{
}
“Copy” event
• The “copy” event executes when the user selects “copy” option with keyboard / mouse.
Syntax:
addEventListener(“copy”, functionname);
function functionname( )
{
}
“Paste” event
• The “paste” event executes when the user selects “paste” option with keyboard / mouse.
Syntax:
addEventListener(“paste”, functionname);
function functionname( )
{
}
“this” keyword
• The “this” keyword represents the “current element”, which has raised the event.
Login - Example
• Validation is a process of checking the form input values, whether those are correct or not.
• If all the form input values are correct, then we will allow the form to be submitted to the server.
• If any one of the form input values are incorrect, then we will stop submitting the form and display
appropriate error message to the user.
• Validations are done using JavaScript.
• Common Examples of Validations:
1. The value can’t be blank.
2. The value should be in the proper format. Ex: phone number, email etc.
3. The value should be within the given range (minimum and maximum).
Ex: Amount should be in between 1000 and 10000 etc.
Example on Validations
Regular Expressions
• Regular expression represents “pattern” of the value.
• Regular expressions are useful in validations, to check whether it is matching with the specified
pattern or not.
1. Internal JavaScript
• Both “html code” and “javascript code” will be written in the same “.html” file.
• Advantage: Easy to understand.
• Disadvantage: The javascript code that is written in “.html” file can’t be used in another html file.
• All the previous programs are the examples of “Internal JavaScript”.
2. External JavaScript
• The javascript code will be written in “.js” file and will be called in one or more “.html” files.
• Advantage: We can call the same “.js” file from many html files (re-usability).
• In realtime, external JavaScript is recommended.
Page1.html
Page2.html
• AJAX is not a language, but it is a “concept”, which is used to “send a background request from
browser to server” and also “get background response from server to browser”, without refreshing
the web page in the browser.
• AJAX allows us to interact with the server and get some data from server, without refreshing the
full web page.
• Ex: Google search, IRCTC search trains.
Advantages of AJAX
• Executes faster.
• Less burden on browser (client) and server.
• User experience is better.
Members of XMLHttpRequest
• XMLHttpRequest class
1. “readyState” property
2. “onreadystatechange” property
3. “responseText” property
4. “open( )” method
5. “send( )” method
open( ) method:
• This method is used to specify the request details such as server url (address), type of the request
(GET / POST).
▪ Server url: The address (url) of server program, to which you want to send request.
▪ Type: Represents type of the request.
Options: GET | POST | PUT | DELETE
send( ) method
o This method sends an asynchronous request (background request) to server.
Syntax: send( )
Example: send( )
readyState
o It represents a number, that represents current status of the request.
Syntax: readyState
Example: readyState
onreadystatechange
o This property stores a callback function, which executes automatically, when the “readyState”
property gets changed.
Syntax: onreadystatechange = functionname;
Example: onreadystatechange = fun1;
responseText
o This property stores the actual response sent from the server to the browser.
o It represents the data in string format.
Syntax: responseText
Example: responseText
c:\ajax
- message.txt
- index.html
c:\ajax\message.txt
c:\ajax\index.html
Execution
• Download and install “nodejs” from “https://nodejs.org”
• Open “Command Prompt” and run the following commands:
cd c:\ajax
npm install http-server -c-0
http-server
• Open browser and enter the url: http://localhost:8080/index.html
c:\ajax
- employee.json
- index.html
c:\ajax\employee.json
c:\ajax\index.html
Execution
• Download and install “nodejs” from “https://nodejs.org”
• Open “Command Prompt” and run the following commands:
cd c:\ajax
npm install http-server -c-0
http-server
• Open browser and enter the url: http://localhost:8080/index.html
c:\ajax
- employees.json
- index.html
c:\ajax\employees.json
c:\ajax\index.html
Execution
• Download and install “nodejs” from “https://nodejs.org”
• Open “Command Prompt” and run the following commands:
cd c:\ajax
npm install http-server -c-0
http-server
• Open browser and enter the url: http://localhost:8080/index.html
Introduction to JavaScript 6
• "JavaScript 6" version in released in 2015, which is also called as "EcmaScript 6 or ES 6".
• JavaScript 6 is the superset of JavaScript 5, which contains the following new features:
1. Classes
2. Constructors
3. Inheritance
4. Method Overriding
5. Set and Get Methods
6. Default Arguments
7. Arrow Functions
8. Let
9. Const
10. Rest
11. Destructuring
12. Multiline Strings
13. String Interpolation
14. Reading Elements from Array
Classes
• "Object" is a "physical item", which is a collection of properties (details) and methods (manipulations).
• "Class" is a "model" of objects, which defines the list of properties and methods of the objects.
Create an object
new classname();
Classes
• "Object" is a "physical item", which is a collection of properties (details) and methods (manipulations).
• "Class" is a "model" of objects, which defines the list of properties and methods of the objects.
Create an object
new classname();
Constructors
• Constructor is a special method in the class, that executes every time when we created an object for
the class.
• Constructor's name should be "constructor".
• Constructor can receive arguments; but can't return any value.
• It is not possible to call the constructor without creating an object.
• Constructors are mainly used to create an initialize properties in the class.
• Parameterized Constructor is a constructor that receives one or more arguments (parameters) and
initializes the same to the respective properties.
Syntax of Constructor
class classname
{
constructor(arguments)
{
}
}
Example on Constructors
Methods
• Method is a function that manipulates data of the object.
Syntax of Method
class classname
{
methodname(arguments)
{
}
}
Example on Methods
Inheritance
• Inheritance is a concept of extending the parent class, by creating the child class.
• When you create an object of child class, all the members of parent class will be automatically added to
the child class's object.
Syntax of Inheritance
class parentclassname
{
constructor(arguments)
{
}
}
Example on Inheritance
Method Overriding
• Method Overriding is a concept of extending the "parent class method", by creating similar method in
the "child class", with same signature (name and arguments).
Default Arguments
• Default Arguments are used to provide a default value for the method of a parameter.
• When we call the method and don’t supply a value for the parameter, the specified default value will be
assigned to the parameter automatically.
Arrow Functions
• "Arrow Functions" are the functions created using "=>" (arrow) operator.
• Arrow Function's "this" keyword reflects the current object; it will not be changed by the caller.
Let
• The "let" keyword can be used as alternative for "var" keyword, to create variables.
• The "var" keyword always creates "local variables" or "block level variables"; but "let" keyword creates
"block level variables".
Example on Let
Const
• The "const" keyword is used to create constants.
• We can't change the value of the constant.
• If you try to change the value of constant, it shows error.
Example on Const
Destructuring
• Destructuring is used to retrieve each value of an array into respective variables.
Example 1 on Destructuring
Example 2 on Destructuring
Example 3 on Destructuring
Multiline Strings
• This concept is used to create a string with multiple lines of text.
• The multiline string should be enclosed within backticks ( ` ` ).
`
line 1
line 2
line 3
…
`
String Interpolation
• "String Interpolation" replaces the expressions in the strin with actual values of the respective variables.
• These strings must be enclosed within backticks ( ` ` ), instead of single quotes ( ' ' ) or double quotes
( " " ).
{
array[i]
}