Web Application Development Overview
Web Application Development Overview
Web Applications
1. Network
- A computer network comprises of group of computers connecting with each other for sharing of
information and devices.
- ARPANET is the first computer network introduced by US-DOD.
[Advanced Research Projects Agency Network]
2. Types of Network
a) LAN [Local Area Network]
b) MAN [Metro politan Area Network]
c) WAN [Wide Area Network]
3. Internet
- Internet is a WAN that connects computer all over the world.
4. Web
- Web is a portion of internet with restricted access.
- CERN labs architect - Tim Berners Lee - Introduced Web. - 1990
- W3C maintains Web Standards.
[Word Wide Web Consortium]
- Web Version is "3" [web-3]
[Link]
Web Application Architecture
1. Data Center
- Database : MongoDB
2. Application Center
- Application : Node JS
- Middleware: Express JS
3. Presentation Center
- Application
HTML
CSS
Bootstrap
Sass
JavaScript
jQuery
Browser Engine
Sudhakar Sharma
HTML
[Hyper Text Markup Language]
- Hyper means Beyond.
- Markup means preparing for presentation.
- HTML is a language used for presentation. It can present the content on browser.
- HTML is a presentation language.
Evolution of HTML:
- CERN labs introduced a language called GML [Generic Markup Language] for presentation.
- CERN introduced SGML [Standard Generic Markup Language] which is more advanced to GML.
- In the early 1990's "Tim Berners Lee" introduced HTML as language.
- A group called "IETF" [Internet Engineering Task Force] developed HTML versions upto 3.1.
- In 2004 WHATWG took the responsibility of HTML.
- HTML is now evolved and maintained by WHATWG.
- WHATWG introduced HTML 4 and HTML 5 Versions. [2014]
[Web Hyper text Application Technology Work Group]
HTML 5
Summary:
GML => SGML => HTML => IETF HTML 3.1 => WHATWG 4.0 => WHATWG HTML 5
Browser Architecture
- Browser is a software tool used by clients in order to access the websites and view on their devices.
- Various Browsers
chrome, edge, firefox, opera, safari etc..
- Browsers are controlled by using Engines
Chrome => V8
Safari => Webkit
FireFox => Gecko, Spider Monkey
Edge => Chakra, Chromium
1. Browser UI
2. Browser Engine
3. Rendering Engine
4. Network
5. JavaScript Interpreter
6. Backend
7. Data Persistance.
HTML Parsing
[Link]
C:\> node -v
C:\> npm -v
[Link]
>npm init -y
a) public
b) src
public : It is used to keep all static resources, like images, html, text, pdf, audio, video..
src : It is used to keep all dynamic resources, like css, js, ts, scss etc..
5. Add a new file into project root folder "[Link]"
6. Click on "Go Live" in status bar
7. Open any browser and request your project URL
[Link]
[Link]
Note: Always use only "command prompt" instead of Power Shell.
<!DOCTYPE html>
<html> start
</html> end
4. Document scope must define the language type for content in page.
</html>
Syntax:
<!DOCTYPE html>
<html lang="en-in">
</html>
Head:
- It defines the content which is intended to load into browser memory and then later delivered to
browser.
- It is good for reusing the content.
- A typical web page in head section comprises of following contents
a) title
b) link
c) meta
d) script
e) style
title:
- It defines a title for page, which is displayed in browser title bar.
- Title is used in SEO [Search Engine Optimization]
- Title is used in booking the page.
Syntax:
<!DOCTYPE html>
<html lang="en-in">
<head>
<title> Online Store - Shopping Online </title>
</head>
</html>
link:
- It is used to link any external document to web page.
- It can link CSS document or Shortcut icon.
<head>
<link rel="shortcut icon" href="public/images/[Link]">
</head>
Static Page:
- Static refers to contineous memory.
- Memory allocated for first object will continue for next object.
- Static page contains same information to display across requests.
- Static page have extention ".html or .htm"
Ex:
[Link]
[Link]
Dynamic Page:
- A dynamic page contains information that changes according to the request.
- It contains information customized for every client request.
- Dynamic page have extentions: .jsp, .php, .asp, .aspx
Ex:
[Link]
[Link]
Note: To design both static and dynamic pages you need HTML.
<!DOCTYPE html>
<html> start
</html> end
4. Document scope must define the language type for content in page.
<html lang="en-in"> en-us, en-gb, en-fr, en-gn
</html>
Syntax:
<!DOCTYPE html>
<html lang="en-in">
</html>
Head:
- It defines the content which is intended to load into browser memory and then later deliverd to
browser.
- It is good for reusing the content.
- A typical web page in head section comprises of following contents
a) title
b) link
c) meta
d) script
e) style
title:
- It defines a title for page, which is displayed in browser title bar.
- Title is used in SEO [Search Engine Optimization]
- Title is used in booking the page.
Syntax:
<!DOCTYPE html>
<html lang="en-in">
<head>
<title> Online Store - Shopping Online </title>
</head>
</html>
link:
- It is used to link any external document to web page.
- It can link CSS document or Shortcut icon.
<head>
<link rel="shortcut icon" href="public/images/[Link]">
</head>
[Link] Declaration
[Link] Scope
[Link] Section
a) title
b) link
c) meta
4. Body Section
Attributes:
1. bgcolor : It sets background color
2. text : It sets text color
a) color name
d) color shade
c) hexa decimal code
#rgb, #rrggbb [0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f]
Syntax:
<body bgcolor="#f00" text="#fff">
Syntax:
<body background="public/images/[Link]">
</body>
background-size
background-position
background-attachment
background-repeat
<head>
<style>
body {
background-size: height, width;
background-position: left, center, right, top, center, bottom;
background-attachment: fixed, scroll;
background-repeat: no-repeat, repeat, repeat-x, repeat-y;
}
</style>
</head>
Ex:
<!DOCTYPE html>
<html lang="en-in">
<head>
<title>Online Store - Shopping Online</title>
<style>
body {
background-size: 800px 800px;
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
}
</style>
</head>
<body background="public/images/[Link]">
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
</body>
</html>
Syntax:
<body align="justify">
</body>
Syntax:
<body alink="red" vlink="gray">
<a href="[Link] Amazon </a>
</body>
7. leftmargin ]
8. rightmargin ] It sets space between your content and browser window.
9. topmargin ]
10. bottommargin ]
Syntax:
<body leftmargin="350" rightmargin="350" topmargin="50" bottommargin="50">
</body>
Body Semantics
- HTML upto version 4 used "tables" for presenting body content.
- Tables are not SEO friendly.
- Tables lead to a situation called "Kiss-of-Death".
- HTML 5 introduced several new semantics to make the body section more SEO friendly and
responsive.
- The semantic elements used for designing layout of page are:
1. header
2. footer
3. section
4. main
5. nav
6. aside
7. article
8. dialog
9. figure
10. figcaption
11. menu
12. div
13. span
14. address
Body Semantics
1. header
- It specifies the content to display at the top margin of page.
- Typically header comprises of
brand name
brand logo
short cut button
search panel
navbar etc...
[Link]
2. div
- It is a container used for division of content in page.
Ex:
<!DOCTYPE html>
<html lang="en-in">
<head>
<title>Home</title>
<style>
div {
border: 1px solid black;
padding: 10px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div>
Web Technologies
<div>
Front End
<div>
HTML <br>
It is a markup language.
</div>
<div>
CSS <br>
It is used for styles.
</div>
</div>
<div>
Back End
<div>
MongoDB <br>
It is a database.
</div>
<div>
Node JS <br>
It is server side scripting.
</div>
</div>
</div>
</body>
</html>
3. span:
- It is used to define inline embedded content.
- It is a inline container.
Syntax:
It is a <span> markup </span> language.
Ex:
<!DOCTYPE html>
<html lang="en-in">
<head>
<title>Home</title>
<style>
div {
border: 1px solid black;
padding: 10px;
margin-bottom: 20px;
}
span {
color:blue;
text-decoration: underline;
}
</style>
</head>
<body>
<div>
Web Technologies
<div>
Front End
<div>
HTML <br>
It is a <span>markup</span> language.
</div>
<div>
CSS <br>
It is used for styles.
</div>
</div>
<div>
Back End
<div>
MongoDB <br>
It is a database.
</div>
<div>
Node JS <br>
It is server side scripting.
</div>
</div>
</div>
</body>
</html>
node_modules/bootstrap-icons/font/[Link]
6. In order to use icons you have to link the CSS file to webpage.
<head>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
Ex:
<!DOCTYPE html>
<html lang="en-in">
<head>
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<span class="bi bi-cart"></span>
<span class="bi bi-person"></span>
<span class="bi bi-house-door"></span>
</body>
</html>
4. nav : It defines navigation area in page.
Ex: [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopper</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
header {
display: flex;
justify-content: space-between;
font-size: 20px;
font-family: Arial;
padding: 15px;
}
span{
margin-right: 20px;
}
.brand-name {
font-size: 30px;
font-weight: bold;
}
article {
background-color: black;
color:white;
font-size: 16px;
padding: 10px;
text-align: center;
margin-top: 10px;
font-family: Arial;
}
.bi-lightning-fill {
color:gold;
}
</style>
</head>
<body>
<header>
<div>
<span class="brand-name">Shopper.</span>
</div>
<div>
<nav>
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Pages</span>
<span>Blog</span>
<span>Docs</span>
</nav>
</div>
<div>
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart4"></span>
</div>
</header>
<article>
<span class="bi bi-lightning-fill"></span>HAPPY HOLIDAY DEALS ON EVERYTHING <span class="bi
bi-lightning-fill"></span>
</article>
</body>
</html>
Sudhakar Sharma
Body Semantics
-header
-div
-span
-nav
-article
footer
- It defines the content to display at the bottom margin of page.
- Usually footer comprises of
Copyrights
Address
Quick Links
Partners
Services etc..
address
- It is used to keep contact details SEO friendly.
Note: In css you can divide content into multiple columns by using "display:grid"
Syntax:
{
display:grid;
grid-template-columns: [share among 12 fr or 1200 px]
}
EX:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopper</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
header {
display: flex;
justify-content: space-between;
font-size: 20px;
font-family: Arial;
padding: 15px;
}
span{
margin-right: 20px;
}
.brand-name {
font-size: 30px;
font-weight: bold;
}
article {
background-color: black;
color:white;
font-size: 16px;
padding: 10px;
text-align: center;
margin-top: 10px;
font-family: Arial;
}
.bi-lightning-fill {
color:gold;
}
section{
height: 200px;
}
footer {
background-color: black;
color:white;
font-size: 15px;
font-family: Arial;
padding: 10px;
display: grid;
grid-template-columns: 2.4fr 2.4fr 2.4fr 2.4fr 2.4fr;
}
.footer-brand-name {
font-size: 30px;
font-weight: bold;
margin-bottom: 20px;
}
.title {
font-weight: bold;
margin-bottom: 20px;
}
.title~div {
margin-bottom: 15px;
}
</style>
</head>
<body>
<header>
<div>
<span class="brand-name">Shopper.</span>
</div>
<div>
<nav>
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Pages</span>
<span>Blog</span>
<span>Docs</span>
</nav>
</div>
<div>
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart4"></span>
</div>
</header>
<article>
<span class="bi bi-lightning-fill"></span>HAPPY HOLIDAY DEALS ON EVERYTHING <span class="bi
bi-lightning-fill"></span>
</article>
<section>
</section>
<footer>
<div>
<div class="footer-brand-name">
<span>Shopper.</span>
</div>
<div>
<span class="bi bi-facebook"></span>
<span class="bi bi-twitter"></span>
<span class="bi bi-instagram"></span>
<span class="bi bi-youtube"></span>
</div>
</div>
<div>
<div class="title">SUPPORT</div>
<div>Contact Us</div>
<div>FAQs</div>
<div>Size Guide</div>
<div>Shipping & Returns</div>
</div>
<div>
<div class="title">SHOP</div>
<div>Men's Shopping</div>
<div>Women's Shopping</div>
<div>Kids' Shopping</div>
<div>Discounts</div>
</div>
<div>
<div class="title">COMPANY</div>
<div>Our Story</div>
<div>Careers</div>
<div>Terms & Conditions</div>
<div>Privacy & Cookie policy</div>
</div>
<div>
<div class="title">CONTACT</div>
<address>
<div>1-202-555-0105</div>
<div>1-202-555-0106</div>
<div>help@[Link]</div>
</address>
</div>
</footer>
</body>
</html>
section
- It defines the content to display between header and footer.
Syntax:
<header> </header>
<section> </section>
<footer> </footer>
main
- It is considered as entry point.
- User start using the application from main area.
- Usually main comprises of actions like register or login.
r-red 0 to 255
g-green 0 to 255
b-blue 0 to 255
a-alpha 0 to 1
rgba(255,0,0,0); red
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
background-size: cover;
}
.shade {
height: 700px;
background-color: rgba(0,0,0,0.5);
margin-top: -20px;
margin-left: -20px;
width: 102%;
}
header {
padding: 30px;
display: flex;
justify-content: space-between;
}
.brand-name {
font-size: 40px;
color:red;
font-family: Arial;
font-weight: bold;
}
.language {
font-size: 20px;
color:white;
}
.signin {
background-color: red;
color:white;
width: 60px;
font-size: 20px;
padding: 5px;
border-radius: 3px;
margin-left: 10px;
height: 23px;
}
.right-panel {
display: flex;
}
section {
color:white;
margin-left: 50px;
}
.title {
font-size: 60px;
font-weight: bold;
font-family: Arial;
margin-top: 100px;
width: 800px;
}
.sub-title {
font-size: 30px;
font-weight: bold;
font-family: Arial;
margin-top: 25px;
}
.email {
height: 25px;
width: 300px;
background-color: black;
color:white;
padding: 10px;
font-size: 20px;
}
.get-started {
background-color: red;
height: 25px;
padding: 10px;
font-size: 20px;
width: 150px;
margin-left: 10px;
}
main {
margin-top: 50px;
}
.main-controls {
display: flex;
margin-top: 20px;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body background="images/[Link]">
<div class="shade">
<header>
<div>
<span class="brand-name">NETFLIX</span>
</div>
<div class="right-panel">
<div class="language"><span class="bi bi-globe"></span>Language</div>
<div class="signin">Signin</div>
</div>
</header>
<section>
<div class="title">Unlimited movies, TV shows and more</div>
<div class="sub-title">Watch anywhere. Cancel anytime.</div>
<main>
<div>Ready to watch? Enter your email to create or restart your membership.</div>
<div class="main-controls">
<div class="email">Your email address</div>
<div class="get-started">Get Started <span class="bi bi-chevron-right"></span> </div>
</div>
</main>
</section>
</div>
</body>
</html>
Sudhakar Sharma
Summary
- header
- footer
- section
- nav
- article
- div
- span
- address
- main
Aside
- It is a container that comprises of information, which is not relative to current context.
- It navigates the user aside the current page.
Syntax:
<aside>
...your ads..
</aside>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inox</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
aside {
position: fixed;
right: 10px;
bottom:10px;
font-size: 25px;
color:darkcyan;
width: 25px;
padding: 3px;
background-color: white;
}
</style>
</head>
<body>
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have an
FAQ page ([Link] that provides
more information, including what Microsoft products and services it covers. Whenever we make
changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
<aside>
<div class="bi bi-facebook"></div>
<div class="bi bi-twitter"></div>
<div class="bi bi-instagram"></div>
<div class="bi bi-youtube"></div>
<div class="bi bi-linkedin"></div>
</aside>
</body>
</html>
Dialog
Syntax:
<dialog open>
... your content...
</dialog>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inox</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
</style>
</head>
<body>
<dialog open>
May I Help you ?
</dialog>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inox</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
nav div {
width: 120px;
background-color: darkcyan;
color:white;
font-size: 16px;
padding: 5px;
margin-bottom: 10px;
border-radius: 10px;
}
nav div:hover {
background-color: black;
cursor:grab;
}
</style>
</head>
<body>
<nav>
<div> <span class="bi bi-house-fill"></span> Home</div>
<div>Kid's Fashion</div>
<div>Women's Fashion</div>
<div>Men's Fashion</div>
<div>Blog</div>
<div>Pages</div>
</nav>
</body>
</html>
Details :
- It is used to create expandable and collapsable content in page.
- The title is defined using "Summary".
Syntax:
<details>
<summary> Title </summary>
........your content...........
</details>
Syntax:
<details open>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inox</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
details div {
width: 100px;
background-color: darkcyan;
color:white;
padding: 4px;
margin-bottom: 10px;
margin-left: 10px;
}
nav {
border:1px solid gray;
padding: 30px;
width: 150px;
height: 200px;
overflow: auto;
}
</style>
</head>
<body>
<nav>
<div> <span class="bi bi-house-fill"></span> Home</div>
<menu>
<details open>
<summary>Electronics</summary>
<div>Televisions</div>
<div>Mobiles</div>
<div>Watches</div>
</details>
<details>
<summary>Footwear</summary>
<div>Casuals</div>
<div>Sneakers</div>
<div>Boots</div>
</details>
</menu>
</nav>
</body>
</html>
Headings
- Headings in page are defined using "<hn>" element.
- "n" refers to level number from 1 to 6.
Syntax:
<h1> Heading 1 </h1>
<h2> Heading 2 </h2>
................
<h6> Heading 6 </h6>
EX:
<body>
<h1>Web Technologies</h1>
<h2>HTML</h2>
It is a markup language.
<h2>CSS</h2>
It defines styles.
<h2>JavaScript</h2>
It manipulates DOM.
</body>
Note:
- Don't use too many headings in a page, it may SPAM your page.
- Don't use headings to highlight any word or sentence in page.
FAQ: How to remove the heading styles for heading element?
Ans: By using CSS inheritance attribute value "unset".
Syntax:
h1 {
font-weight:unset;
}
h1 {
all : unset;
}
FAQ: Can we change the font size and styles for heading?
Ans: Yes.
Syntax:
h1 {
font-family : Brush Script MT;
font-size: 60px;
}
Syntax:
nav{
display:flex;
justify-content:space-between;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
nav {
display: flex;
justify-content: space-between;
}
</style>
</head>
<body>
<nav>
<h2>HTML</h2>
<h2>CSS</h2>
<h2>JavaScript</h2>
</nav>
</body>
</html>
Sudhakar Sharma
Syntax:
<blockquote>
... summary ....
</blockquote>
<p> Para-1 </p>
<p> Para-2 </p>
<p> Para-3 </p>
Syntax:
<font face="" size="" color=""> Text </font>
Ex:
<font face="Magneto" size="6" color="#f00">
Welcome to HTML
</font>
Ex:
<p><font size="7" face="Magneto" color="#f00">Welcome to HTML</font></p>
Note: Finally at the time of publishing website page can't have review tags.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
blockquote {
margin-left: 300px;
margin-right: 300px;
font-style: italic;
}
</style>
</head>
<body>
<div>
Celebrating 12<sup>th</sup> Anniversary
</div>
<div>
H<sub>2</sub>O
</div>
<div>
Font style <b>Bold</b> is similar to <strong>Strong.</strong>
</div>
<div>
Font style <i>Italics</i> is similar to <em>Emphasized.</em>
</div>
<div>
Font Effect <u>Underline</u> is same as <ins>Inserted</ins>.
</div>
<div>
<strike>Strikeout</strike> is same as <del> Deleted. </del>
</div>
</body>
</html>
Syntax:
p{
text-indent : 50px;
}
Syntax:
p{
line-height : 20px;
letter-spacing: 5px;
word-spacing: 10px;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
p{
text-indent: 50px;
line-height: 30px;
letter-spacing: 2px;
word-spacing: 10px;
}
</style>
</head>
<body>
<p align="justify">
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
</p>
</body>
</html>
Syntax:
p :: first-letter {
font-size : 50px;
float:left;
color:red;
font-weight:bold;
font-family:Arial;
}
HTML Orderd and Unordered List
Sudhakar Sharma
Syntax:
<ol>
<li>Item-1</li>
<li>Item-2</li>
</ol>
Attributes:
type It defines numbering type: 1, A, a, i, I
<ol type="A">
Ex:
<body>
<h2>Web Technologies</h2>
<ol type="1" reversed start="2">
<li>HTML</li>
<li>CSS</li>
<li>Bootstrap</li>
<li>JavaScript</li>
</ol>
</body>
Syntax:
<ol type="1">
<li> Item-1
<ol type="a">
<li> Child-1 </li>
<li> Child-2 </li>
</ol>
</li>
</ol>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
</style>
</head>
<body>
<h2>Web Technologies</h2>
<ol type="1">
<li>HTML
<ol type="a">
<li>Document Declaration</li>
<li>Document Scope</li>
</ol>
</li>
<li>CSS
<ol type="a">
<li>Selectors</li>
<li>Units
<ol type="i">
<li>Relative Units</li>
<li>Absolute Units</li>
</ol>
</li>
<li>Colors</li>
</ol>
</li>
</ol>
</body>
</html>
Attribute:
type disc, circle, square
<ul type="disc">
<li> Item-1 </li>
<li> Item-2 </li>
</ul>
FAQ's:
1. How to display list item side-by-side?
A. By using CSS display-flex.
Syntax:
ol {
display:flex;
}
EX:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
.options-list {
display: flex;
margin-top: 10px;
}
.options-list li {
margin-right: 50px;
}
</style>
</head>
<body>
<ol type="1">
<li>What is the role of CSS?
<ol type="a" class="options-list">
<li>DOM Manipulation</li>
<li>DOM Presentation</li>
<li>Responsive DOM</li>
<li>None</li>
</ol>
</li>
</ol>
</body>
</html>
Syntax:
ol {
display:flex;
grid-template-columns: 6fr 6fr;
}
ol {
columns: 2;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
.options-list {
columns:2;
margin-top: 10px;
}
.options-list li {
margin-right: 50px;
}
</style>
</head>
<body>
<ol type="1">
<li>What is the role of CSS?
<ol type="a" class="options-list">
<li>DOM Manipulation</li>
<li>DOM Presentation</li>
<li>Responsive DOM</li>
<li>None</li>
</ol>
</li>
</ol>
</body>
</html>
3. How to create scrollable list?
A. By defining border, height and overflow.
Syntax:
ol {
border: 1px solid gray;
width:100px;
height:55px;
overflow: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
ol {
border:1px solid gray;
width: 100px;
height: 55px;
overflow: auto;
}
</style>
</head>
<body>
<ol type="1">
<li>HTML</li>
<li>CSS</li>
<li>Bootstrap</li>
<li>Sass</li>
<li>JavaScript</li>
<li>jQuery</li>
<li>Angular</li>
<li>React</li>
</ol>
</body>
</html>
Syntax:
ol , ul {
list-style : none;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
footer {
background-color: black;
color:white;
padding: 20px;
display: grid;
grid-template-columns: 3fr 3fr 3fr 3fr;
}
ol {
list-style: none;
}
li {
margin-bottom: 10px;
}
</style>
</head>
<body>
<footer>
<ol>
<h4>Get to Know Us</h4>
<li>About Us</li>
<li>Careers</li>
<li>Press Releases</li>
<li>Amazon Science</li>
</ol>
</footer>
</body>
</html>
Syntax:
<li class="bi bi-tag"> </li>
ul {
list-style-image: url("images/[Link]");
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Headings</title>
<style>
ul {
list-style-image: url("images/[Link]");
font-size: 34px;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<footer>
<ul>
<li > About Us</li>
<li > Careers</li>
<li > Press Releases</li>
<li > Amazon Science</li>
</ul>
</footer>
</body>
</html>
Syntax:
ol {
list-style-type : circle|disc|square;
}
ul {
list-style-type: number|upper-alpha|lower-roman;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flipkart</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
.product {
font-family: Arial;
display: grid;
grid-template-columns: 2fr 9fr 3fr;
}
h3 {
color:blue;
}
.rating{
background-color: green;
color:white;
padding: 2px;
border-radius: 5px;
}
ul {
margin-left: -30px;
}
li {
color:gray;
margin-bottom: 10px;
}
.right-panel div {
margin-bottom: 15px;
}
</style>
</head>
<body>
<div class="product">
<div>
</div>
<div>
<h3>realme C55 (Rainforest, 128 GB)</h3>
<div>
<span class="rating">4.4 <span class="bi bi-star-fill"></span></span> <span class="ratings-
count"><b><font color="gray">12,315 Ratings & 661 Reviews</font></b></span>
</div>
<ul type="disc">
<li>8 GB RAM | 128 GB ROM | Expandable Upto 1 TB</li>
<li>17.07 cm (6.72 inch) Full HD+ Display</li>
<li>64MP + 2MP | 8MP Front Camera</li>
<li>5000 mAh Battery</li>
<li>Helio G88 Processor</li>
<li>1 Year Manufacturer Warranty for Phone and 6 Months Warranty for In the Box
Accessories</li>
</ul>
</div>
<div class="right-panel">
<div> <font face="Arial" size="6"><b>₹ 13,999</b></font> </div>
<div>
<strike><font color="gray"><b>₹ 15,999</b></font></strike> <font
color="green"><b> 15% Off</b></font>
</div>
<div>
Free delivery by <b>Today</b>
</div>
<div>
<b><font color="green">Saver Deals</font></b>
</div>
<div>
Upto <b>₹ 13,000 </b> off on exchange
</div>
</div>
</div>
</body>
</html>
HTML Images
Sudhakar Sharma
Images in HTML
- Images in computer technologies are of various types.
- Web will not support all types of images.
- Web supports following types of images
Attributes:
1. src It defines the image path and name
2. alt It defines the alternate text to display when image fails to load.
3. title It defines the tip to display when mouse is over image.
4. width & height Sets width and height for image
5. border It sets border by specified pixels
6. align It aligns image left or right. It is used for content beside image.
7. vspace It defines vertical space ] between text
8. hspace It defines horizontal space ] and image
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<img align="left" vspace="10" hspace="10" src="images/[Link]" width="150" height="150">
<img align="right" src="images/[Link]" width="150" height="150">
<p>Depending on how you obtained the Windows software, this is a license agreement between
(i) you and the device manufacturer or software installer that distributes the software with your
device; or (ii) you and Microsoft Corporation (or, based on where you live or, if a business, where
your principal place of business is located, one of its affiliates) if you acquired the software from a
retailer. Microsoft is the device manufacturer for devices produced by Microsoft or one of its
affiliates, and Microsoft is the retailer if you acquired the software directly from Microsoft. Note that
if you are a volume license customer, use of this software is subject to your volume license
agreement rather than this agreement.</p>
<p>Depending on how you obtained the Windows software, this is a license agreement between
(i) you and the device manufacturer or software installer that distributes the software with your
device; or (ii) you and Microsoft Corporation (or, based on where you live or, if a business, where
your principal place of business is located, one of its affiliates) if you acquired the software from a
retailer. Microsoft is the device manufacturer for devices produced by Microsoft or one of its
affiliates, and Microsoft is the retailer if you acquired the software directly from Microsoft. Note that
if you are a volume license customer, use of this software is subject to your volume license
agreement rather than this agreement.</p>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flipkart</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
.product {
font-family: Arial;
display: grid;
grid-template-columns: 3fr 6fr 3fr;
column-gap: 20px;
margin-bottom: 20px;
border-bottom: 3px solid gray;
}
h3 {
color:blue;
}
.rating{
background-color: green;
color:white;
padding: 2px;
border-radius: 5px;
}
ul {
margin-left: -30px;
}
li {
color:gray;
margin-bottom: 10px;
}
.right-panel div {
margin-bottom: 15px;
}
</style>
</head>
<body>
<div class="product">
<div>
<img title="25% OFF - Offer valid upto 18-June-2023" alt="realme mobile - images blocked on
your browser" width="100%" height="300" src="images/[Link]">
</div>
<div>
<h3>realme C55 (Rainforest, 128 GB)</h3>
<div>
<span class="rating">4.4 <span class="bi bi-star-fill"></span></span> <span class="ratings-
count"><b><font color="gray">12,315 Ratings & 661 Reviews</font></b></span>
</div>
<ul type="disc">
<li>8 GB RAM | 128 GB ROM | Expandable Upto 1 TB</li>
<li>17.07 cm (6.72 inch) Full HD+ Display</li>
<li>64MP + 2MP | 8MP Front Camera</li>
<li>5000 mAh Battery</li>
<li>Helio G88 Processor</li>
<li>1 Year Manufacturer Warranty for Phone and 6 Months Warranty for In the Box
Accessories</li>
</ul>
</div>
<div class="right-panel">
<div> <font face="Arial" size="6"><b>₹ 13,999</b></font> </div>
<div>
<strike><font color="gray"><b>₹ 15,999</b></font></strike> <font
color="green"><b> 15% Off</b></font>
</div>
<div>
Free delivery by <b>Today</b>
</div>
<div>
<b><font color="green">Saver Deals</font></b>
</div>
<div>
Upto <b>₹ 13,000 </b> off on exchange
</div>
</div>
</div>
<div class="product">
<div>
<img title="25% OFF - Offer valid upto 18-June-2023" alt="realme mobile - images blocked on
your browser" width="100%" height="300" src="images/[Link]">
</div>
<div>
<h3>realme C55 (Sunshower, 128 GB)</h3>
<div>
<span class="rating">4.4 <span class="bi bi-star-fill"></span></span> <span class="ratings-
count"><b><font color="gray">12,315 Ratings & 661 Reviews</font></b></span>
</div>
<ul type="disc">
<li>8 GB RAM | 128 GB ROM | Expandable Upto 1 TB</li>
<li>17.07 cm (6.72 inch) Full HD+ Display</li>
<li>64MP + 2MP | 8MP Front Camera</li>
<li>5000 mAh Battery</li>
<li>Helio G88 Processor</li>
<li>1 Year Manufacturer Warranty for Phone and 6 Months Warranty for In the Box
Accessories</li>
</ul>
</div>
<div class="right-panel">
<div> <font face="Arial" size="6"><b>₹ 13,999</b></font> </div>
<div>
<strike><font color="gray"><b>₹ 15,999</b></font></strike> <font
color="green"><b> 15% Off</b></font>
</div>
<div>
Free delivery by <b>Today</b>
</div>
<div>
<b><font color="green">Saver Deals</font></b>
</div>
<div>
Upto <b>₹ 13,000 </b> off on exchange
</div>
</div>
</div>
</body>
</html>
1. crossorigin : It is defined for images, which are access from remote servers
[API]
a) allow-anonymous
b) use-credentials
Sudhakar Sharma
Images in HTML
- Various Image Types
- Purpose of different types
- Basic Attributes
src, alt, title, width, height, border, align, vspace, hspace.
- Advanced Attributes
1. crossorigin
Syntax:
<img crossorigin="allow-anonymous | use-credentials" src="...">
2. decoding : It defines how image loads along with other content in page.
It have the values "async | sync | auto"
Syntax:
<img decoding="async | sync | auto" src="....">
Syntax:
<img importance="low|high|medium|auto" src="..">
Note: To keep the images in page SEO friendly you can use the semantic elements
<figure>
<figcaption>
Syntax:
<figure>
<img src="images/[Link]" width="200" height="300">
<figcaption> Realme - Summer Offer 50% OFF </figcaption>
</figure>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
figure {
padding: 10px;
border:1px solid gray;
width: 250px;
}
figcaption {
width: 60%;
font-style: italic;
}
</style>
</head>
<body>
<figure>
<img importance="high" src="images/[Link]" width="100" height="100">
<figcaption>Realme - 50% OFF - Summer Offer</figcaption>
</figure>
</body>
</html>
<div class="card">
<div class="card-header">
<img src="images/[Link]" width="100%" height="150">
</div>
<div class="card-body">
<p>[Link]</p>
<div class="rating">
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
</div>
</div>
<div class="card-footer">
<div class="btn">
Join Course
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<img src="images/[Link]" width="100%" height="150">
</div>
<div class="card-body">
<p>Android Training</p>
<div class="rating">
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
</div>
</div>
<div class="card-footer">
<div class="btn">
Join Course
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<img src="images/[Link]" width="100%" height="150">
</div>
<div class="card-body">
<p>PHP Training</p>
<div class="rating">
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
<span class="bi bi-star-fill"></span>
</div>
</div>
<div class="card-footer">
<div class="btn">
Join Course
</div>
</div>
</div>
</div>
</body>
</html>
Ex: Amazon-Cards
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Amazon Cards</title>
<style>
section {
display: grid;
grid-template-columns: 3fr 3fr 3fr 3fr;
margin-top: -300px;
}
.card {
height: 450px;
margin: 5px;
padding: 5px;
background-color: white;
box-shadow: 2px 2px 2px gray;
}
.card-header {
font-size: 20px;
font-family: Arial;
font-weight: bold;
}
.card-footer {
color:blue;
font-size: 16px;
}
.row-1 {
font-size: 20px;
font-weight: bold;
font-family: Arial;
}
.row-2, .row-3 {
display: grid;
grid-template-columns: 6fr 6fr;
column-gap: 10px;
}
.row-4 {
font-size: 16px;
color:blue;
}
</style>
</head>
<body>
<header>
<img src="images/[Link]" width="100%">
</header>
<section>
<div class="card">
<div class="card-header">
<p>Bluetooth Calling Smartwatch starts at...</p>
</div>
<div class="card-body">
<img src="images/[Link]" height="300">
</div>
<div class="card-footer">
<p>see more</p>
</div>
</div>
<div class="card">
<div class="row-1">
<p>Appliances for your home | Up to 55% off</p>
</div>
<div class="row-2">
<div>
<img src="images/[Link]" width="100%">
<p>Air Conditioners</p>
</div>
<div>
<img src="images/[Link]" width="200">
<p>Refrigrators</p>
</div>
</div>
<div class="row-3">
<div>
<img src="images/[Link]" width="200">
<p>Microwave Oven</p>
</div>
<div>
<img src="images/[Link]" width="200">
<p>Washing Machine</p>
</div>
</div>
<div class="row-4">
see more
</div>
</div>
<div class="card">
<div class="row-1">
<p>Appliances for your home | Up to 55% off</p>
</div>
<div class="row-2">
<div>
<img src="images/[Link]" width="100%">
<p>Air Conditioners</p>
</div>
<div>
<img src="images/[Link]" width="200">
<p>Refrigrators</p>
</div>
</div>
<div class="row-3">
<div>
<img src="images/[Link]" width="200">
<p>Microwave Oven</p>
</div>
<div>
<img src="images/[Link]" width="200">
<p>Washing Machine</p>
</div>
</div>
<div class="row-4">
see more
</div>
</div>
<div class="card">
<div class="row-1">
<p>Appliances for your home | Up to 55% off</p>
</div>
<div class="row-2">
<div>
<img src="images/[Link]" width="100%">
<p>Air Conditioners</p>
</div>
<div>
<img src="images/[Link]" width="100%">
<p>Refrigrators</p>
</div>
</div>
<div class="row-3">
<div>
<img src="images/[Link]" width="200">
<p>Microwave Oven</p>
</div>
<div>
<img src="images/[Link]" width="200">
<p>Washing Machine</p>
</div>
</div>
<div class="row-4">
see more
</div>
</div>
</section>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tempalte Cards</title>
<style>
.container {
display: flex;
justify-content: space-around;
}
.card {
width: 300px;
box-shadow: 2px 2px 2px gray;
border:1px solid black;
padding: 5px;
}
.card-img {
width: 100px;
height: 100px;
padding-right: 10px;
}
.card-header {
display: flex;
}
.card-body {
font-family: Arial;
color:gray;
line-height: 25px;
}
.card-footer {
color:gray;
font-weight: bold;
font-family: Arial;
}
.card:hover {
height: 350px;
background-color: black;
color:white;
}
</style>
</head>
<body>
<div class="container">
<div class="card">
<div class="card-header">
<img src="images/[Link]" class="card-img">
<div>
<p>Shoes</p>
<h4>Low top Sneakers</h4>
</div>
</div>
<div class="card-body">
<p>The Microsoft Services Agreement is an agreement between you and Microsoft (or one
of its affiliates) that governs your use of Microsoft consumer online products and services.</p>
</div>
<div class="card-footer">
Logan Edwards, 16 Jun 2023
</div>
</div>
<div class="card">
<div class="card-header">
<img src="images/[Link]" class="card-img">
<div>
<p>Shoes</p>
<h4>Low top Sneakers</h4>
</div>
</div>
<div class="card-body">
<p>The Microsoft Services Agreement is an agreement between you and Microsoft (or one
of its affiliates) that governs your use of Microsoft consumer online products and services.</p>
</div>
<div class="card-footer">
Logan Edwards, 16 Jun 2023
</div>
</div>
<div class="card">
<div class="card-header">
<img src="images/[Link]" class="card-img">
<div>
<p>Shoes</p>
<h4>Low top Sneakers</h4>
</div>
</div>
<div class="card-body">
<p>The Microsoft Services Agreement is an agreement between you and Microsoft (or one
of its affiliates) that governs your use of Microsoft consumer online products and services.</p>
</div>
<div class="card-footer">
Logan Edwards, 16 Jun 2023
</div>
</div>
</div>
</body>
</html>
Body Semantics
Sudhakar Sharma
1. Normal Elements
2. Void Elements
3. RC Data Elements
4. Raw Text Elements
5. Foreign Elements
Normal Elements:
- These are the elements that return a presentation directly on callback.
- They doesn't require additional attributes.
- They start presentation but will not stop the presentation.
- You have to explicitly stop by using end token.
Ex:
<b> start token
</b> end token
Void Elements:
- These are the elements that discard the return values.
- Void refers to "discard return value". [no return]
- These elements doesn't require end token.
- They return any presentation only by using additional attributes.
Ex: <img>
RC Data Elements:
- These are Rich Content data elements.
- They will not allow to present any another element with in the context.
- They are ment for only plain text content.
Foreign Elements:
- These are HTML elements, but not native to browser.
- We have to enable plugin's explicitly to use these elements.
- They need additional library to enable and use.
Syntax:
H T M L <br>
It is a markup language.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
pre {
background-color: black;
color:white;
padding: 10px;
width: 400px;
}
</style>
</head>
<body>
<h3>Sample C Program</h3>
<div>
<pre>
#include <stdio.h>
main()
{
printf("Welcome to C programming");
}
</pre>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
</head>
<body>
<h3>Find the Largest among 3</h3>
<h5>Explanation:</h5>
<samp>
<b>Test Case 1 :</b> Write a function that take 3 values. <br>
<b>Test Case 2 :</b> Write a condition to evaluate largest of 3.
</samp>
<h5>Your Code</h5>
<code>
<pre>
function FindLargest(<var>a</var>, <var>b</var>, <var>c</var>)
{
}
</pre>
</code>
</body>
</html>
Ex:
<big>Large</big>
<small>Small</small>
Hyper Links
Links in HTML
Sudhakar Sharma
Hyperlinks in HTML
- Link is clickable text, picture or graphic that navigates the user to any specific location when clicked.
- Navigation is the process of re-directing the user from one location to another.
- Hyper mean's beyond.
- A Hyperlink provides content beyond what you see, which can be accessed by clicking on link.
- Hyperlinks are created in HTML by using "anchor" <a> element.
Syntax:
<span> Home </span> Normal Text
<span> <a> Home </a> </span> Hyperlink
<a> Text | Picture | Graphic </a> Hyperlink
<h2 id="home">
<img id="pic">
<ol id="topics">
<div id="container">
- You can reach to any reference ID by accessing "# id reference name" from address bar.
[Link]
- You can create a Hyperlink that sets the URL with "# and ID reference".
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intra Links</title>
<style>
header {
background-color: darkcyan;
color:white;
padding: 5px;
text-align: center;
}
section {
display: grid;
grid-template-columns: 3fr 9fr;
}
ul {
list-style: none;
margin-left: -40px;
}
li {
width: 150px;
background-color: darkcyan;
color:white;
font-size: 20px;
padding: 3px;
margin-bottom: 20px;
}
main {
height: 400px;
overflow: auto;
}
nav a {
color:white;
text-decoration: none;
}
.btn-back {
width: 200px;
background-color: black;
color:white;
padding: 3px;
text-align: center;
}
.btn-back a {
color:white;
text-decoration: none;
}
</style>
</head>
<body>
<header>
<h2>Shopper</h2>
</header>
<section>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#men">Men's Fashion</a></li>
<li><a href="#women">Women's Fashion</a></li>
<li><a href="#kids">Kid's Fashion</a></li>
</ul>
</nav>
<main>
<h2 id="home">Home</h2>
<p>We understand that <span><b><a href="#offer">Realme Offers</a></b></span> you may
have questions about the Microsoft Services Agreement. We have an FAQ page
([Link] that provides more
information, including what Microsoft products and services it covers. Whenever we make changes,
we provide a summary of the most notable changes to the current Microsoft Services Agreement.
We will also continue to provide a summary of the changes to the previous version, and a link to the
previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
</main>
</section>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intra Links</title>
<style>
header {
background-color: darkcyan;
color:white;
padding: 5px;
text-align: center;
}
section {
display: grid;
grid-template-columns: 3fr 9fr;
}
ul {
list-style: none;
margin-left: -40px;
}
li {
width: 150px;
background-color: darkcyan;
color:white;
font-size: 20px;
padding: 3px;
margin-bottom: 20px;
}
main {
height: 400px;
overflow: auto;
}
nav a {
color:white;
text-decoration: none;
}
.btn-back {
width: 200px;
background-color: black;
color:white;
padding: 3px;
text-align: center;
}
.btn-back a {
color:white;
text-decoration: none;
}
.header-nav {
display: flex;
justify-content: center;
}
.header-nav img {
margin-right: 30px;
border:2px solid white;
box-shadow: 2px 2px 2px gray;
}
</style>
</head>
<body>
<header>
<h2>Shopper</h2>
<div class="header-nav">
<div>
<a href="#men"><img src="images/[Link]" width="50" height="50"></a>
</div>
<div>
<a href="#women"> <img src="images/[Link]" width="50" height="50"></a>
</div>
<div>
<a href="#kids"> <img src="images/[Link]" width="50" height="50"></a>
</div>
</div>
</header>
<section>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#men">Men's Fashion</a></li>
<li><a href="#women">Women's Fashion</a></li>
<li><a href="#kids">Kid's Fashion</a></li>
</ul>
</nav>
<main>
<h2 id="home">Home</h2>
<p>We understand that <span><b><a href="#offer">Realme Offers</a></b></span> you may
have questions about the Microsoft Services Agreement. We have an FAQ page
([Link] that provides more
information, including what Microsoft products and services it covers. Whenever we make changes,
we provide a summary of the most notable changes to the current Microsoft Services Agreement.
We will also continue to provide a summary of the changes to the previous version, and a link to the
previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
</main>
</section>
</body>
</html>
FAQ: How to highlight the target if page contents are not scrollable?
Ans : By using CSS class called "target". It can identify the target location and apply effects using ID
reference.
Syntax:
div {
// effects on normal state
}
div:target {
// effects on target
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intra Links</title>
<style>
.topic {
width: 300px;
background-color: lightgray;
border:1px solid black;
box-shadow: 2px 2px 2px gray;
padding: 5px;
margin: 20px;
}
.topic:target {
background-color: black;
color:white;
font-size: 25px;
transition: 2s;
}
.container {
display: flex;
}
ul {
list-style: none;
display: flex;
}
li {
margin-right: 100px;
background-color: black;
color:white;
padding: 5px;
width: 100px;
text-align: center;
font-size: 20px;
}
nav {
display: flex;
justify-content: center;
}
a{
color:White;
text-decoration: none;
}
</style>
</head>
<body>
<nav>
<ul>
<li><a href="#html">HTML</a></li>
<li><a href="#css">CSS</a></li>
<li><a href="#js">JavaScript</a></li>
</ul>
</nav>
<div class="container">
<div class="topic" id="html">
<h2>HTML</h2>
<p>It is a markup language.</p>
<p>It is used for presentation.</p>
</div>
<div class="topic" id="css">
<h2>CSS</h2>
<p>It configures styles.</p>
<p>Styles make interactive design.</p>
</div>
<div class="topic" id="js">
<h2>JavaScript</h2>
<p>It is a programming language.</p>
<p>It manipulates DOM.</p>
</div>
</div>
</body>
</html>
a{
text-decoration: none;
}
<body vlink="gray">
a:visited {
color:gray;
}
a:link {
color:white;
}
a{
color:white;
}
Inter Document Links
Sudhakar Sharma
Syntax: File
<a href="[Link]"> Text </a>
- You can link any type of file. [ image, doc, ppt, xls, pdf, avi, mp3, mp4..]
Note: Every file type can't open in browser. It requires special "plugin's" to open various types of
files. If plugin is not installed in browser, then the linked document will download.
Syntax: URL
Syntax: Application
91 = country code
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inter Document Link</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<ol>
<li><a href="./[Link]">Courses</a></li>
<li><a href="./images/[Link]">Realme</a></li>
<li><a href="./docs/[Link]">Arrays PDF Tutorial</a></li>
<li><a href="./docs/Complete [Link]">Array Word Document</a></li>
<li><a href="./images/[Link]" download="asp-net">[Link]</a></li>
<li><a href="[Link] HTML</a></li>
<li>Contact : <a href="hr@[Link]">hr@[Link]</a></li>
<li>Call : <a href="[Link]
<li>Skype : <a href="skype:hr_nareshit@[Link]"><span class="bi
bi-skype"></span></a></li>
<li>Whatsup : <a href="[Link]
</ol>
</body>
</html>
Syntax:
<a href="./images/[Link]" target="_blank"> Realme </a>
Syntax:
<a href="javascript:[Link]('path', 'title', 'features')">
Ex:
<a href="javascript:[Link]('./images/[Link]', 'RealMe', 'width=300 height=400')">
Realme </a>
FAQ: How to open linked document in the same window along with existing content?
Ans: By using <iframe> from HTML 5.
Syntax:
<iframe name="refName" src="path" width="" height=""> </iframe>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inter Document Link</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
section {
display: grid;
grid-template-columns: 4fr 8fr;
}
iframe {
border:none;
}
</style>
</head>
<body>
<section>
<nav>
<ol>
<li><a href="./[Link]">Courses</a></li>
<li><a href="javascript:[Link]('./images/[Link]','RealMe','width=300
height=400')" >Realme</a></li>
<li><a href="./images/[Link]" target="framebody">Realme-1</a></li>
<li><a href="./docs/[Link]" target="_blank">Arrays PDF Tutorial</a></li>
<li><a href="./docs/Complete [Link]">Array Word Document</a></li>
<li><a href="./images/[Link]" download="asp-net">[Link]</a></li>
<li><a href="[Link] HTML</a></li>
<li>Contact : <a href="hr@[Link]">hr@[Link]</a></li>
<li>Call : <a href="[Link]
<li>Skype : <a href="skype:hr_nareshit@[Link]"><span class="bi
bi-skype"></span></a></li>
<li>Whatsup : <a href="[Link]
<li><a href="[Link]
target="framebody">AWS Training Video</a></li>
<li><a href="[Link] target="framebody">DS
Training</a></li>
</ol>
</nav>
<main>
<iframe name="framebody" width="100%" height="400"></iframe>
</main>
</section>
</body>
</html>
[Link]
[Link]
[Link]
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<figure>
<iframe width="300" src="[Link]
height="300"></iframe>
<figcaption>AWS</figcaption>
</figure>
<figure>
<iframe width="300" height="300"
src="[Link]
<figcaption>DS Training</figcaption>
</figure>
</body>
</html>
Sudhakar Sharma
Summary
- Hyperlink
- Intra document
- Inter document
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
.bi-list {
font-size: 30px;
}
header {
display: flex;
justify-content: space-between;
}
.search-bar {
display: flex;
}
.search-text-box {
width: 500px;
border:1px solid gray;
height: 25px;
padding: 5px;
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
}
.bi-search {
padding: 5px;
border:1px solid gray;
height: 25px;
width: 50px;
border-top-right-radius: 20px;
border-bottom-right-radius: 20px;
text-align: center;
background-color: lightgray;
}
.bi-mic-fill {
padding: 10px;
}
.short-hand-buttons span {
margin-right: 20px;
font-size: 20px;
}
.channel-logo {
border-radius: 80px;
height: 25px;
width: 25px;
border:2px solid black;
}
section {
margin-top: 40px;
display: grid;
grid-template-columns: 1fr 11fr;
height: 500px;
overflow: auto;
}
nav div {
font-size: 30px;
margin-bottom: 50px;
}
.channel-description {
margin-top: 50px;
display: grid;
grid-template-columns: 2fr 8fr 2fr;
}
.channel-title-container {
width: 600px;
padding: 20px;
}
.channel-title {
font-size: 30px;
font-family: Arial;
}
.channel-subtitle {
font-size: 18px;
margin-top: 10px;
color:gray;
font-family: Arial;
}
.subscribe-button {
background-color: black;
color:white;
font-size: 20px;
padding: 5px;
text-align: center;
border-radius: 20px;
}
.channel-navigation {
display: flex;
justify-content: space-around;
font-family: Arial;
color:gray;
font-weight: bold;
}
.channel-highlights {
margin-top: 50px;
display: grid;
grid-template-columns: 5fr 7fr;
column-gap: 30px;
}
.highlights-video {
width: 100%;
height: 250px;
}
ul {
list-style: none;
margin-left: -40px;
}
li {
font-family: Arial;
font-size: 16px;
margin-bottom: 10px;
color:gray;
}
.row {
display: grid;
grid-template-columns: 3fr 3fr 3fr 3fr;
column-gap: 10px;
margin-bottom: 100px;
}
</style>
</head>
<body>
<header>
<div>
<span class="bi bi-list"></span>
<img src="images/[Link]" width="100">
</div>
<div class="search-bar">
<div class="search-text-box"> Search </div>
<div class="bi bi-search"></div>
<div class="bi bi-mic-fill"></div>
</div>
<div class="short-hand-buttons">
<span class="bi bi-camera-video"></span>
<span class="bi bi-bell"></span>
<img src="images/[Link]" width="50" class="channel-logo">
</div>
</header>
<section>
<nav>
<div class="bi bi-house-door"></div>
<div class="bi bi-camera-reels"></div>
<div class="bi bi-lightning-charge"></div>
<div class="bi bi-collection-play"></div>
</nav>
<main>
<div>
<img src="images/[Link]" width="100%">
</div>
<div class="channel-description">
<div>
<img src="images/[Link]">
</div>
<div class="channel-title-container">
<div class="channel-title">Naresh i Technologies</div>
<div class="channel-subtitle">@NareshIT1.1M subscribers2.8K videos</div>
<p>We are one of the India's largest software training organization and an Top 5 of Best
Software Training Institutes...</p>
</div>
<div>
<div class="subscribe-button">Subscribe</div>
</div>
</div>
<div class="channel-navigation">
<div>HOME</div>
<div>VIDEOS</div>
<div>SHORTS</div>
<div>LIVE</div>
<div>PLAYLISTS</div>
<div>COMMUNITY</div>
<div>CHANNELS</div>
<div>ABOUT</div>
</div>
<article class="channel-highlights">
<div>
<iframe src="[Link] class="highlights-
video"></iframe>
</div>
<div>
167,998 views 3 years ago
<p>Best Software Training Institute with Placements - Naresh i Technologies</p>
<ul>
<li>SQL Server @ 6.00 Pm : [Link]
<li>Attend a Free Demo On Full Stack Data Science </li>
<li>Python @ 11.00 AM :- [Link]
<li>Ui Full Stack Web DevelopMent @ 8.30 AM </li>
</ul>
</div>
</article>
<div class="our-videos">
<div class="row">
<iframe></iframe>
<iframe></iframe>
<iframe></iframe>
<iframe></iframe>
</div>
<div class="row">
<iframe></iframe>
<iframe></iframe>
<iframe></iframe>
<iframe></iframe>
</div>
</div>
</main>
</section>
</body>
</html>
Sudhakar Sharma
Syntax:
<dl>
<dt> Term-1 </dt>
<dd> Definition </dd>
<dt> Term-2 </dt>
<dd> Definition </dd>
</dl>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
dt {
background-color: gray;
color:white;
font-weight: bold;
padding: 5px;
margin-bottom: 10px;
text-align: left;
}
</style>
</head>
<body>
<h2>Web Technolgoies</h2>
<dl>
<dt>HTML</dt>
<dt>Markup</dt>
<dd> It is a markup language. </dd>
<dd> It is used for presentation.</dd>
<dt>CSS </dt>
<dd>It defines styles. </dd>
<dt>JavaScript </dt>
<dd>It manipulates DOM. </dd>
</dl>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
dt {
background-color: gray;
color:white;
font-weight: bold;
padding: 5px;
margin-bottom: 10px;
text-align: left;
}
dl {
display: grid;
grid-template-columns: 2fr 10fr;
}
dd {
background-color: darkcyan;
color:white;
padding: 5px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd>some name</dd>
<dt>Age</dt>
<dd>some age</dd>
<dt>Address</dt>
<dd>some contact</dd>
<dt>Email</dt>
<dd>some@[Link]</dd>
</dl>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
dt {
background-color: black;
color:white;
width: 150px;
padding: 5px;
position: sticky;
top: 0px;
}
</style>
</head>
<body>
<h1>Shopper.</h1>
<dl>
<dt>Electronics</dt>
<dd>Mobiles</dd>
<dd>Televisions</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>Televisions</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>Televisions</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>Televisions</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>Televisions</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>Televisions</dd>
<dd>Watches</dd>
<dt>Footwear</dt>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dd>Casuals</dd>
<dd>Boots</dd>
<dd>Sneakers</dd>
<dt>Fashion</dt>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
<dd>Kids</dd>
<dd>Men</dd>
<dd>Women</dd>
</dl>
</body>
</html>
Syntax:
<fieldset>
<legend> Title </legend>
....................
...................
</fieldset>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
dl {
display: grid;
grid-template-columns: 2fr 8fr;
}
dt {
background-color: darkcyan;
color: white;
padding: 5px;
margin-bottom: 5px;
}
dd {
background-color: gray;
color:white;
padding: 5px;
margin-bottom: 5px;
}
fieldset {
margin-bottom: 25px;
box-shadow: 4px 4px 2px black;
}
legend {
background-color: darkcyan;
color:white;
text-align: center;
padding: 5px;
font-weight: bold;
box-shadow: 2px 2px 2px gray;
width: 120px;
border-radius: 20px;
}
</style>
</head>
<body>
<fieldset>
<legend>Personal Details</legend>
<dl>
<dt>User Name</dt>
<dd>some name</dd>
<dt>Age</dt>
<dd>some age</dd>
<dt>Date of Birth</dt>
<dd>some date</dd>
</dl>
</fieldset>
<fieldset>
<legend>Contact Details</legend>
<dl>
<dt>Address</dt>
<dd>some contact</dd>
<dt>Email</dt>
<dd>some@[Link]</dd>
<dt>Mobile</dt>
<dd>4999919293</dd>
</dl>
</fieldset>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
legend {
text-align: center;
padding-left: 10px;
padding-right: 10px;
}
fieldset {
width: 50%;
border-left: none;
border-right: none;
border-bottom: none;
}
</style>
</head>
<body>
<fieldset>
<legend> New to Amazon? </legend>
</fieldset>
</body>
</html>
Tables in HTML
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table</title>
<style>
td img {
border-radius: 50px;
}
</style>
</head>
<body>
<table width="500" border="1">
<caption>Product List</caption>
<colgroup span="3" style="background-color: yellow;"></colgroup>
<thead>
<tr>
<th>Preview</th>
<th>Name</th>
<th>Price</th>
<th>Stock</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="images/[Link]" width="50" height="50">
</td>
<td>Watches</td>
<td>₹ 1000 to ₹ 40,000</td>
<td>Available</td>
</tr>
<tr>
<td>
<img src="images/[Link]" width="50" height="50">
</td>
<td>AC</td>
<td>₹ 1000 to ₹ 40,000</td>
<td>Available</td>
</tr>
<tr>
<td>
<img src="images/[Link]" width="50" height="50">
</td>
<td>Refrig</td>
<td>₹ 1000 to ₹ 40,000</td>
<td>Available</td>
</tr>
</tbody>
<tfoot>
<tr>
<td> </td>
<td>Copyright</td>
<td>2023</td>
<th> </th>
</tr>
</tfoot>
</table>
</body>
</html>
Table Attributes:
1. frame, rules & border
<table border="0">
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table</title>
<style>
td img {
border-radius: 50px;
}
</style>
</head>
<body>
<table width="500" border="1" frame="void">
<caption>Product List</caption>
<colgroup span="3"></colgroup>
<thead>
<tr>
<th>Preview</th>
<th>Name</th>
<th>Price</th>
<th>Stock</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="images/[Link]" width="50" height="50">
</td>
<td>Watches</td>
<td>₹ 1000 to ₹ 40,000</td>
<td>Available</td>
</tr>
<tr>
<td>
<img src="images/[Link]" width="50" height="50">
</td>
<td>AC</td>
<td>₹ 1000 to ₹ 40,000</td>
<td>Available</td>
</tr>
<tr>
<td>
<img src="images/[Link]" width="50" height="50">
</td>
<td>Refrig</td>
<td>₹ 1000 to ₹ 40,000</td>
<td>Available</td>
</tr>
</tbody>
<tfoot>
<tr>
<td> </td>
<td>Copyright</td>
<td>2023</td>
<th> </th>
</tr>
</tfoot>
</table>
</body>
</html>
Sudhakar Sharma
Table Elements
<table>
<caption>
<colgroup>
<thead>
<tbody>
<tfoot>
<tr>
<td>
<th>
Table Attributes
1. frame, rules and border
<table background="images/[Link]">
<tr background="images/[Link]">
<table align="center">
<thead align="center">
<tr align="right">
<td align="center">
<tr valign="top">
<td valign="center">
Note: Height and Valign are not available for table as properties. They are configured
only as attributes.
Note: You can define rowspan and colspan only for <td> or <th>.
<th colspan="3">
<td rowspan="6">
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<font face="Arial">
<table width="100%" border="1" cellspacing="5" cellpadding="5">
<thead>
<tr>
<th colspan="2">Name</th>
<th colspan="3">Address</th>
</tr>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>State</th>
<th>Postal Code</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td rowspan="6" align="center">D<br>E<br>L<br>H<br>I</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5" align="center">© copyright 2023</td>
</tr>
</tfoot>
</table>
</font>
</body>
</html>
Summary:
1. frame
2. border
3. rules
4. cellspacing
5. cellpadding
6. bgcolor
7. background
8. align
9. valign
10. width
11. height
12. rowspan
13. colspan
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table width="100%" cellspacing="10" cellpadding="5" border="1" frame="void">
<tr height="100">
<td colspan="3">header</td>
</tr>
<tr height="400">
<td width="200">
<table height="300" width="200" cellpadding="5" cellspacing="20" border="1"
frame="void">
<tr align="center">
<td><a href="[Link]" target="framebody">Home</a></td>
</tr>
<tr align="center">
<td>Men</td>
</tr>
<tr align="center">
<td>Women</td>
</tr>
</table>
</td>
<td><iframe width="100%" name="framebody" src="[Link]"
height="400"></iframe></td>
<td width="50">Aside</td>
</tr>
<tr height="50">
<td colspan="3"></td>
</tr>
</table>
</body>
</html>
Forms
Forms in HTML
Sudhakar Sharma
Forms in HTML
- Form provides an UI that allows the user to interact with our application.
- Interaction is the process where user inputs a value, application will process the request and
generates a response customized for every client request.
- Form is a container with set of elements like
button
textbox
checkbox
radio
listbox
dropdown etc..
- HTML form is designed by using <form> element. It is a container element.
- It can collect the input from user and submit to server.
Form Attributes:
1. id : It is a unique reference given for form.
2. name : It is a reference name given for form, which is not unique.
3. class : It defines a CSS class, which sets effects for element.
4. method : It defines the actions performed by form element.
Every form have only 2 methods to perform
a) GET
b) POST
POST
- It is a request method used to submit data.
- The data submitted on POST will be in "Form Body".
- Form Body is not visible to all users.
- It is safe.
- It is hard to hack your data.
- It is not stored in browser logs.
- It can't be bookmarked.
- There is no limit for submitting data.
- You can submit any type of complex data i.e binary.
- It can't cache the data.
Syntax:
<form method="post" action="[Link]|asp..">
</form>
Sudhakar Sharma
syntax:
<form method="get" novalidate>
</form>
FAQ's
1. Can a page have multiple forms?
A. Yes.
Form Elements
- A form comprises of various elements like
textbox, checkbox, radio, listbox, dropdown, etc..
TextBox
- It is an input element that allows the user to view, edit and input a value.
- Textbox is used for "string" input.
- String is a literal with group of chars : alphabet, number, special chars.
- Textbox marks every input as string.
10 => "10"
- To design textbox element HTML provides "<input>" token with "type" as text.
Note: <input> is element and type defines data type for input, string type is "text".
Syntax:
<input type="text">
Attributes:
1. id
2. name
3. class
Note: Form can't submit the value of any element if "name" is not defined.
Hence name is mandatory for every element in form.
Attributes don't have any order dependency.
Syntax:
<input type="text" id="uname" class="form-control" name="UserName">
You can't submit any element value if its idefined outside form container.
5. readonly : It will not allow to change the value but can submit the value.
Syntax:
<input type="text" name="OTP" size="6">
8. placeholder : It defines the watermark text for textbox. It is displayed only when
value is not defined.
Syntax:
<input type="text" size="40" placeholder="Search [Link]">
Syntax:
<input type="text" autofocus name="UserName">
10. required : It is a validation attribute, which will not allow to submit if value
is not defined.
Syntax:
<input type="text" name="UserName" required>
Syntax:
<input type="text" name="UserName" required minlength="4" maxlength="10">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
dt {
font-weight: bold;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<form method="get">
<div align="center">
<h1>Google</h1>
<p>
<input type="text" name="search" size="40" list="terms">
<datalist id="terms">
<option>JavaScript Examples</option>
<option>CSS Examples</option>
<option>HTML Tutorial</option>
<option>JavaScript Tutorial</option>
<option>HTML Projects</option>
<option>CSS Projects</option>
</datalist>
</p>
<p>
<button>Search</button>
</p>
</div>
</form>
</body>
</html>
14. pattern
Sudhakar Sharma
Summary
id, name, class, size, value, readonly, disabled, placeholder, autofocus, required, minlength,
maxlength, list
pattern
Meta Characters:
Syntax:
pattern="colou?r" => color, colour
Syntax:
pattern="colou*r" => color, colour, colouur, colouuur..
Syntax:
pattern="colou+r" => colour, colouur,...
Syntax:
pattern=".at" => cat, bat, rat, #at, 6at
pattern=".o." => cow, dos, 8o$
Syntax:
pattern="red|blue|green" => only specified words
Syntax:
pattern="[A-Z]"
pattern="[0-9]"
pattern="[A,D,S]"
pattern="[a,d,s,A,D,S]"
pattern="[a-z, A-Z]"
pattern="[$,%,#]"
Syntax:
pattern="(?=.*)"
Syntax:
pattern="gmail\.com"
pattern="\+91"
Syntax:
pattern="\^ your expression $"
Syntax:
pattern="[^A,D,S]" => all chars other than A,D,S
Syntax:
pattern="\d" => 1,2,3,4,..
pattern="\d\d" => 10, 20, 11, 23
pattern="\d\d?" => 1, 10,
Syntax:
pattern="\D" => a, A, @, #
pattern="\D\d" => A2, $2,
Syntax:
pattern="\w"
pattern="\w\d"
Syntax:
pattern="\W"
pattern="\W\w"
Syntax:
pattern="\d\s\D" => 4 $, 4 A, 4 a
\i It is used to ignore the capitalization of string.
[ignore case]
Syntax:
pattern="colou?r\i" => color, Color
Quantifiers
{n} It refers exactly specified number of chars
Syntax:
pattern="\d{2}"
pattern="\w{4}"
pattern="\d{2}\D{1}
Syntax:
pattern="\d{4,8}"
Syntax:
pattern="\d{4, }"
pattern="SBIN00\d{5}"
Q. Write a pattern to validate mobile number starting with +91 and 10 digits.
pattern="\+91\d{10}"
pattern="\+91[0-9]{10}"
pattern="\w{4,15}"
[Link] a pattern to validate US mobile format
+(1)(425) 555-0100
pattern="\+\(1\)\(\d{3}\)\s\d{3}-\d{4}"
Form Elements
Sudhakar Sharma
Patterns
- Regular Expression
- Meta Characters
- Quantifiers
Password
- It is similar to text box but it can mask the chars with "*"
- All attributes are same as textbox but not supported with "list" attribute.
- You can design password input by using the type as "password".
Syntax:
<input type="password" id="pwd" name="password" placeholder="Min 4 chars" minlength="4"
maxlength="15" required pattern="[A-Z]{4,15}">
Number
- It allows only numeric values to input.
- The additional attributes for number type
Syntax:
<input type="number" name="Age" min="15" max="30" value="22" step="1">
<input type="number" name="Rate" min="10.45" max="18.45" value="10.45" step="0.01">
Range
- It is similar to number input, but displays a slider instead of numeric selector.
- Attributes
min
max
value
step
Syntax:
<input type="range" name="Rate" min="10.45" max="18.45" step="0.01">
Email
- It is an input element that validates the email address.
- You can use all textbox attributes.
Syntax:
<input type="email" name="Email" required>
URL
- It validates the URL input.
- Every URL must have protocol and domain address.
http://
https://
Syntax:
<input type="url" name="url" required>
Color
- It can display a color picker, so that user can select any color.
- It can use only 6 char hexa decimal code for colors.
- You can set default color using "value" attribute.
Syntax:
<input type="color" name="color" value="#ff0000">
File
- It can add a file browser, which allows the user to select a file from client machine.
- It is not a file uploader. It is just a file selector.
Syntax:
<input type="file" name="photo">
- You can set filter for selecting files by using "accept" attribute.
Syntax:
<input type="file" name="photo" accept=".jpg">
<input type="file" name="photo" accept=".jpg, .png, .gif">
- You can allow to select more than one file by using "multiple" attribute.
Syntax:
<input type="file" name="photos" accept=".jpg" multiple>
Date and Time
- It can display a date or time picker, so that user select choose date and time.
- There are various types for date and time
date
datetime-local
time
month
year
week
- It will not allow to select range of dates.
- You can set restriction of date range by using the attributes "min & max".
- The default date format in any computing system is "year-month-day".
Syntax:
<input type="date" name="date" min="2023-06-28" max="2023-07-14">
Radio Buttons
- A radio button allows user to select one or multiple options from a group of choices.
- Radio button once checked can't be unchecked.
- To handle radio buttons you have to implement "Mutex" mechanism.
[Mutual Exclusion]
- To define mutex all radios in one category must have same name.
Syntax:
<input type="radio" name="gender"> Male
<input type="radio" name="gender"> Female
Sudhakar Sharma
Form Elements
- TextBox
- Password
- Number
- Range
- Color
- Email
- File
- URL
- Date, DateTime-Local, Month, Year
- Radio [name, value, checked]
CheckBox
- It allows the user to check and uncheck any option.
- User can select one or multiple from a group of choices.
- All attributes are same like radio, but common name will not add "Mutex".
Syntax:
<input type="checkbox" name="course" value="Web Design" checked> Web Design
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
ul {
list-style: none;
border:1px solid gray;
padding: 10px;
width: 100px;
height: 50px;
overflow: auto;
}
</style>
</head>
<body>
<form method="get">
<dl>
<dt>Select Course</dt>
<dd>
<ul>
<li><input type="checkbox" name="Course" value="UI"> Web UI</li>
<li> <input type="checkbox" name="Course" checked value="Oracle"> Oracle</li>
<li><input type="checkbox" name="Course" value=".NET"> .NET </li>
<li><input type="checkbox" name="Course" value="Java"> Java </li>
</ul>
</dd>
</dl>
<button>Submit</button>
</form>
</body>
</html>
Dropdown List
- It can display a list of options from where user can choose any one option.
- It provides a dropdown menu that expands when user clicks on menu button.
- The elements used for dropdown
<select>
<optgroup>
<option>
Syntax:
<select>
<option> Choose Item </option>
<optgroup label="Title">
<option> Item-1 </option>
<option> Item-2 </option>
</optgroup>
</select>
- Every <option> is RC data type, It can display only plain text, number, special char.
It can't display complex formats and elements inside.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<form method="get">
<h3><span class="bi bi-person-fill"></span> Register User</h3>
<dl>
<dt>Select Airport</dt>
<dd>
<select name="Airport">
<option>Select Airport</option>
<option value="RGI">Rajiv Gandhi Int. Airport [Hyd]</option>
</select>
</dd>
<dt>Select City</dt>
<dd>
<select name="City">
<option>Select Your City</option>
<option>Delhi</option>
<option>Hyd</option>
</select>
</dd>
<dt>Select Product</dt>
<dd>
<select name="Product">
<option>Select Product</option>
<optgroup label="Electronics">
<option>Televisions</option>
<option selected>Mobiles</option>
</optgroup>
<optgroup label="Fashion">
<option>Kids</option>
<option disabled>Men's</option>
<option>Women's</option>
</optgroup>
</select>
</dd>
</dl>
<button>Submit</button>
</form>
</body>
</html>
ListBox
- It allows the user to select one or multiple options from a group of choices.
- A dropdown list is transformed into listbox by using the attributes:
a) multiple
b) size
- Elements are same
<select>
<optgroup>
<option>
Syntax:
<select size="2">
<select multiple size="3">
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
Textarea
- It is used for multiline text.
- It is similar to textbox but can display text in multiple lines.
- It is RC data type.
- Attributes
name, readonly, disabled, rows, cols
Syntax:
<textarea rows="4" cols="40"> </textarea>
<textarea rows="4" cols="30" readonly>
.... your text....
</textarea>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
Meter
- It is used to display a grade meter.
- It is controlled dynamically by using script.
- It have attributes
min
max
value
low
high
Syntax:
<meter min="1" max="100" value="100"> </meter>
<meter min="1" max="100" value="20"> </meter>
<meter min="1" max="100" value="100" low="60" high="80"> </meter> RED
<meter min="1" max="100" value="100" low="40" high="80"> </meter> Gold
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
meter {
width: 200px;
height: 20px;
}
meter+span {
color:gray;
}
ul {
list-style: none;
}
li {
margin-bottom: 10px;
}
</style>
</head>
<body>
<form method="get">
<ul>
<li>5 <span class="bi bi-star-fill"></span> <meter min="1" value="5" max="5"></meter>
<span>10,206</span> </li>
<li>4 <span class="bi bi-star-fill"></span> <meter min="1" max="5" value="4"></meter>
<span>2,206</span> </li>
<li>3 <span class="bi bi-star-fill"></span> <meter min="1" low="40" high="80" max="100"
value="100"></meter> <span>206</span> </li>
<li>2 <span class="bi bi-star-fill"></span> <meter min="1" low="60" high="80" max="100"
value="100"></meter> <span>16</span> </li>
</ul>
</form>
</body>
</html>
progress
- It is used to display the status of any task performed in page, like downloading, copying, uploading,
installing etc..
- Attributes
min
max
value
Syntax:
<progress min="1" max="100" value="20"> </progress>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
progress {
width: 300px;
height: 40px;
}
</style>
</head>
<body>
<form method="get">
<dl>
<dt>Preparing for Download</dt>
<dd><progress></progress></dd>
<dt>40% Completed</dt>
<dd><progress min="1" max="100" value="40"></progress></dd>
<dt>80% Completed</dt>
<dd><progress min="1" max="100" value="80"></progress></dd>
<dt>Download Completed</dt>
<dd><progress min="1" max="100" value="100"></progress></dd>
</dl>
</form>
</body>
</html>
Label
- It is used to display titles and caption for any element, which makes the element SEO friendly.
Syntax:
<label for="fieldName"> Text </label>
<div>
<input type="text" name="fieldName">
</div>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 500px;
}
form {
border:1px solid gray;
padding: 20px;
box-shadow: 2px 2px 2px black;
font-family: Arial;
width: 200px;
}
.form-group {
margin-bottom: 20px;
}
input, button {
width: 100%;
height: 25px;
}
button {
background-color: black;
color:white;
}
label {
font-weight: bold;
margin-bottom: 3px;
}
</style>
</head>
<body>
<form method="get">
<h3><span class="bi bi-person-fill"></span>User Login</h3>
<div class="form-group">
<label for="UserName">User Name</label>
<div>
<input type="text" name="UserName">
</div>
</div>
<div class="form-group">
<label for="Password">Password</label>
<div>
<input type="password" name="Password">
</div>
</div>
<div class="form-group">
<button>Login</button>
</div>
</form>
</body>
</html>
Sudhakar Sharma
Buttons
- User can confirm any action by using buttons.
- HTML buttons are classified into 2 types
a) Generic
b) Non Generic
Submit ] Generic
Reset ] Buttons
- You can design and add buttons into page using versions
a) HTML 4
b) HTML 5
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form method="get">
<dl>
<dt>User Name</dt>
<dd><input type="text" name="User"> </dd>
<dt>Course</dt>
<dd>
<input type="checkbox" checked name="course"> HTML <br>
<input type="checkbox" name="course"> JavaScript <br>
</dd>
</dl>
<input type="submit" value="Register">
<input type="reset" value="Cancel">
<input type="button" value="Print">
</form>
</body>
</html>
- HTML 5 Buttons support complex data, which includes formats and images.
Note: If type is not defined for HTML 5 <button> then the default is "Submit" type.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<form method="get">
<dl>
<dt>User Name</dt>
<dd><input type="text" name="User"> </dd>
<dt>Course</dt>
<dd>
<input type="checkbox" checked name="course"> HTML <br>
<input type="checkbox" name="course"> JavaScript <br>
</dd>
</dl>
<button type="submit"><span class="bi bi-person"></span> Register</button>
<button type="reset"><span class="bi bi-c-circle"></span>Cancel</button>
<button type="button"> <img src="images/[Link]" width="30" height="50"> </button>
</form>
</body>
</html>
Summary
<form>
<input> [text, password, number, email, url, range, file, color, button, checkbox, radio]
<select>
<option>
<optgroup>
<datalist>
<textarea>
<meter>
<progress>
<button>
<label>
- Bootstrap provides various CSS classes for presenting different types of HTML components.
1. Container Classes
.container mobile
.container-sm tab
.container-lg pc
.container-xl laptop [1200px]
.container-xxl wide screen laptop [1600px]
.container-fluid changes according to device
<body class="container">
<div class="container-fluid">
<form class="container-xl">
2. Margins
.m margin all directions
.ms left margin
.me right margin
.mt top margin
.mb bottom margin
.m-{size} 1 to 4
3. Padding
.p padding all directions
.ps padding left
.pe padding right
.pt padding top
.pb padding bottom
.p-{size} 1 to 4
4. Border
.border
.border-{size} 1 to 3
.border-{contextual} => primary, dark, secondary, danger, success, warning, info
.rounded [border radius]
.rounded-{size} 1 to 3
.rounded-circle
.rounded-pill
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<img src="images/[Link]" class="m-4 rounded-circle" width="100" height="100">
<form method="get" class="mt-4 ms-4 border border-3 border-primary rounded rounded-3 p-4 w-
25">
<dl>
<dt>User Name</dt>
<dd><input type="text" name="User"> </dd>
<dt>Course</dt>
<dd>
<input type="checkbox" checked name="course"> HTML <br>
<input type="checkbox" name="course"> JavaScript <br>
</dd>
</dl>
<button class="me-4" type="submit"><span class="bi bi-person"></span> Register</button>
<button class="me-4" type="reset"><span class="bi bi-c-circle"></span>Cancel</button>
</form>
</body>
</html>
5. Buttons
.btn
.btn-{contextual}
.btn-outline-{contextual}
.btn-sm
.btn-lg
.btn-group
.btn-group-vertical
.btn-toolbar
.btn-link
.btn-close
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h2>Navigation</h2>
<nav class="btn-toolbar bg-danger justify-content-between">
<div class="btn-group">
<button class="btn btn-danger">Shopper.</button>
</div>
<div class="btn-group">
<button class="btn btn-danger">Home</button>
<button class="btn btn-danger">Pages</button>
<button class="btn btn-danger">Shop</button>
<button class="btn btn-danger">Blog</button>
</div>
<div class="btn-group">
<button class="btn btn-danger"><span class="bi bi-person-fill"></span></button>
<button class="btn btn-danger"><span class="bi bi-heart"></span></button>
<button class="btn btn-danger"><span class="bi bi-bell"></span></button>
</div>
</nav>
<h2>Buttons</h2>
<dl>
<dt>Button Base Class</dt>
<dd><button class="btn">Submit</button></dd>
<dt>Contextual</dt>
<dd>
<button class="btn btn-primary">Insert</button>
<button class="btn btn-warning">Update</button>
<button class="btn btn-danger">Delete</button>
</dd>
<dt>Outline Contextual</dt>
<dd>
<button class="btn btn-outline-primary">Insert</button>
<button class="btn btn-outline-warning btn-sm">Update</button>
<button class="btn btn-outline-danger btn-lg">Delete</button>
</dd>
<dt>Button Group</dt>
<dd class="btn-group-vertical">
<button class="btn btn-danger"><span class="bi bi-facebook"></span></button>
<button class="btn btn-danger"><span class="bi bi-twitter"></span></button>
<button class="btn btn-danger"><span class="bi bi-instagram"></span></button>
</dd>
<dt>Special Button</dt>
<dd>
<button class="btn btn-link">Signout</button>
<button class="btn-close"></button>
</dd>
</dl>
</body>
</html>
Sudhakar Sharma
Jul 1, 2023
6. Form Classes
.form-control text,number,password, url, date, email, textarea
.form-range range
.form-check-input radio, checkbox
.form-label label
.form-check-label label for radio and checkbox
.form-select select element
.form-control-color color
.form-control-file file
.form-switch switch style for checkbox and radio [defined for container]
(It is for container that contains radio and checkbox)
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 700px;
}
</style>
</head>
<body class="container-fluid">
<form class="border border-2 border-primary p-3 rounded w-25">
<h4>Register Product</h4>
<div class="mb-3">
<label class="form-label">Product Name</label>
<div>
<input type="text" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label">Price</label>
<div>
<input type="number" class="form-control">
</div>
</div>
<div class="mb-3">
<label class="form-label">Shipped To</label>
<div>
<select class="form-select">
<option>Choose City</option>
<option>Delhi</option>
<option>Hyd</option>
</select>
</div>
</div>
<div class="mb-3">
<label class="form-label">Rating</label>
<div>
<input class="form-range" type="range" min="1" max="5" value="1">
</div>
</div>
<div class="mb-3">
<label class="form-label">Stock</label>
<div class="form-switch">
<input type="checkbox" class="form-check-input"> <label class="form-check-
label">Available</label>
</div>
</div>
<div class="mb-3">
<label class="form-label">Select Color</label>
<div>
<input type="color" class="form-control-color">
</div>
</div>
<div class="mb-3">
<button class="btn btn-primary w-100">Register</button>
</div>
</form>
</body>
</html>
6. Input Group
.input-group
.input-group-lg
.input-group-text
Syntax:
<div class="input-group">
<span class="input-group-text"> Text </span>
<input type="text" class="form-control">
<span class="input-group-text"> Text </span>
</div>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Input Group</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body class="container-fluid">
<h3>Amazon Search Bar</h3>
<div class="w-50">
<div class="input-group">
<select class="input-group-text">
<option>All</option>
<option>Mobiles</option>
</select>
<input class="form-control" type="text" placeholder="Search [Link]">
<button class="btn btn-warning">
<span class="bi bi-search"></span>
</button>
</div>
</div>
<h3>Netflix Register</h3>
<div class="w-50 bg-dark p-4">
<div class="input-group input-group-lg">
<input type="email" class="form-control" placeholder="Your email address">
<button class="ms-2 btn btn-danger">
Get Started <span class="bi bi-chevron-right"></span>
</button>
</div>
</div>
<h3>Verify Password</h3>
<div class="w-50">
<div class="input-group">
<span class="bi bi-key-fill input-group-text"></span>
<input type="password" class="form-control">
<span class="bi bi-check-circle input-group-text"></span>
</div>
</div>
<h3>Verify User</h3>
<div class="w-50">
<div class="input-group">
<span class="bi bi-person-fill input-group-text"></span>
<input type="text" class="form-control">
<span class="bi bi-check-circle input-group-text"></span>
</div>
</div>
</body>
</html>
.text-{contextual}
.bg-{contextual}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input:required+span {
display: block;
color:red;
}
input+span{
display: none;
}
</style>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" ><span>Name Required</span></dd>
<dt>Password</dt>
<dd><input type="password" required ><span>Password Required</span></dd>
<dt>Age</dt>
<dd><input type="number"><span>Age Required</span></dd>
</dl>
<button>Register</button>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input:required+span {
display: block;
color:red;
}
input:required {
border:1px solid red;
}
input+span{
display: none;
}
</style>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" required ><span>Name Required</span></dd>
<dt>Password</dt>
<dd><input type="password" required ><span>Password Required</span></dd>
<dt>Age</dt>
<dd><input type="number"><span>Age Required</span></dd>
</dl>
<button>Register</button>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input:required+span {
display: block;
color:red;
}
input:required {
border:1px solid red;
}
input+span{
display: none;
}
#Age:in-range+span {
display: none;
}
#Age:out-of-range+span {
display: block;
color:red;
}
</style>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" required ><span>Name Required</span></dd>
<dt>Password</dt>
<dd><input type="password" required ><span>Password Required</span></dd>
<dt>Age</dt>
<dd><input type="number" id="Age" min="15" max="30"><span>Age 15 to 30
only</span></dd>
</dl>
<button>Register</button>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#Age:in-range+span {
display: none;
}
#Age:out-of-range+span {
display: block;
color:red;
}
#Password:invalid+span {
display: block;
color:red;
}
#Password:valid+span {
display: none;
}
#UserName:valid+span{
display: none;
}
#UserName:invalid+span{
display: block;
color:red;
}
</style>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" id="UserName" required><span>User Name Required</span></dd>
<dt>Password</dt>
<dd><input type="password" id="Password" pattern="[A-Z]{4,10}"><span>Password 4 to 10
Uppercase only</span></dd>
<dt>Age</dt>
<dd><input type="number" id="Age" min="15" max="30"><span>Age 15 to 30
only</span></dd>
</dl>
<button>Register</button>
</body>
</html>
Sudhakar Sharma
•
Jul 3, 2023
FAQ: How to configure a form field, which is not displayed in page but can submit a value?
Ans : By using <input type="hidden">
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form>
<h3>Edit User Details</h3>
<dl>
<dt><input type="hidden" name="UserId" value="john_nit"></dt>
<dt>User Name</dt>
<dd><input type="text" value="John" name="UserName"></dd>
<dt>Age</dt>
<dd><input type="number" value="22" name="Age"></dd>
</dl>
<button>Save</button>
</form>
</body>
</html>
Multimedia
- It refers to audio, video and animations.
- HTML provides few multi-media elements like
<marquee>
<audio>
<video>
<embed>
Marquee
- It is used to display scrolling and sliding content in page.
Syntax:
<marquee>
... your content .....
</marquee>
Attributes:
1. scrollamount : It controls the marquee scrolling speed from 1 to 100.
<marquee scrollamount="20"> your content </marquee>
<marquee behavior="alternate">
4. width & height : It defines width and height for marquee content.
<marquee loop="3">
<marquee bgcolor="red">
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<marquee scrollamount="20" loop="3">
Season End Sale <img src="images/[Link]" width="50" height="50"> 70% off on select products
</marquee>
<marquee direction="up" width="100" height="400" bgcolor="yellow">
<div>
<img src="images/[Link]" width="100" height="100">
</div>
<div>
<img src="images/[Link]" width="100" height="100">
</div>
<div>
<img src="images/[Link]" width="100" height="100">
</div>
<div>
<img src="images/[Link]" width="100" height="100">
</div>
</marquee>
</body>
</html>
Syntax:
<video src="path" controls poster="[Link]"> </video>
[width , height]
<embed src="path"> HTML 4 version
Syntax:
<audio src="path" controls poster="[Link]"> </audio>
Ex:
<body>
<h2>Class Video</h2>
<video src="videos/[Link]" poster="images/[Link]" controls width="300"
height="300"></video>
</body>
Styles
- Styles are additional attributes defined for HTML elements to make them more interactive and
responsive.
1. Inline Styles
2. Embedded Styles
3. External Style Sheets
Inline Styles:
- The style attributes are defined with in the element start tag by using "style" attribute.
Syntax:
<h2 style="color:red; background-color:yellow; border:1px solid black">
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1 style="color:red; background-color: yellow; text-align: center;">HTML</h1>
<h1>JavaScript</h1>
<h1>Bootstrap</h1>
</body>
</html>
Embedded Styles:
Syntax:
<head>
<style>
... your attributes...
</style>
</head>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
h1{
background-color: yellow;
color: red;
text-align: center;
}
</style>
</head>
<body>
<h1>HTML</h1>
<h1>JavaScript</h1>
<h1>Bootstrap</h1>
</body>
</html>
Sudhakar Sharma
Jul 4, 2023
1. Inline Styles
2. Embedded
FAQ's:
1. Where to embed the styles, in <head> or <body> section?
A. You can embed styles in both head and body.
Syntax:
<style type="text/css">
</style>
Syntax:
<style type="text/css" media="print | screen | speech | all">
</style>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css" media="screen">
.ticket {
border:1px solid red;
box-shadow: 2px 2px 2px yellow;
padding: 20px;
background-color: lightcyan;
}
.ticket h2 {
text-align: center;
font-size: 30px;
font-family: Arial;
color:blue;
}
dl {
display: grid;
grid-template-columns: 6fr 6fr;
}
dt,dd {
background-color: darkcyan;
color:white;
padding: 4px;
margin-bottom: 10px;
}
.offer {
position: absolute;
top: 50px;
right: 50px;
background-color: red;
color:white;
width: 100px;
padding: 20px;
border-radius: 20px;
}
</style>
<style type="text/css" media="print">
.ticket {
background-color: none;
border:none;
box-shadow: none;
}
dl {
display: grid;
grid-template-columns: 12fr;
}
dt, dd {
background-color: black;
color:white;
margin-bottom: 10px;
}
.offer, marquee {
display: none;
}
</style>
</head>
<body>
<div class="offer">Offer 70% Off</div>
<div class="ticket">
<h2>Ticket</h2>
<dl>
<dt>Departure Time</dt>
<dd>07:30 PM</dd>
<dt>Boarding Point</dt>
<dd>Hyd Airport</dd>
</dl>
<marquee bgcolor="yellow">Please carry a soft copy of your ticket</marquee>
</div>
</body>
</html>
Note: Issue with embedded technique is, the styles are not accessible to other pages.
You can reuse only within the page not accross pages.
Ex:
- Create a new folder "src\styles"
- Add a new file
"[Link]"
.ticket {
border:1px solid red;
box-shadow: 2px 2px 2px yellow;
padding: 20px;
background-color: lightcyan;
}
.ticket h2 {
text-align: center;
font-size: 30px;
font-family: Arial;
color:blue;
}
dl {
display: grid;
grid-template-columns: 6fr 6fr;
}
dt,dd {
background-color: darkcyan;
color:white;
padding: 4px;
margin-bottom: 10px;
}
.offer {
position: absolute;
top: 50px;
right: 50px;
background-color: red;
color:white;
width: 100px;
padding: 20px;
border-radius: 20px;
}
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../src/styles/[Link]">
</head>
<body>
<div class="offer">Offer 70% Off</div>
<div class="ticket">
<h2>Ticket</h2>
<dl>
<dt>Departure Time</dt>
<dd>07:30 PM</dd>
<dt>Boarding Point</dt>
<dd>Hyd Airport</dd>
</dl>
<marquee bgcolor="yellow">Please carry a soft copy of your ticket</marquee>
</div>
</body>
</html>
FAQ's:
1. How to link a stylesheet to page?
A. By using <link> element
3. What is Minification?
A. It is a programming technique used by developers to compress the CSS code
and reduce the file size.
You can minify the code using various minification tools:
[Link]
Ex:
1. Open any minification tool online
[Link]
6. Paste the minified code and link the minified file to page.
Sudhakar Sharma
Jul 5, 2023
Rules
1. If styles are defined to any element by using all 3 techniques, then which set of styles are applied?
A.
- If same attributes are defined then it will apply according to priority
1st Inline
2nd Embedded
3rd External File
- If different attributes are defined then all will apply.
2. If styles are defined to any element using multiple style containers in head and body then which
set of styles are applied?
A.
-If same attributes are defined then the latest will apply.
- If different attributes are defined then all will apply.
How styles are defined for HTML element? How a browser selects HTML element and applies the
styles?
A.
- If styles are written inline then they will apply only for current element.
- If styles are written embedded or in external file then the selectors will decide where to apply the
effects.
Syntax:
<style type="text/css">
selector
{
attribute : value;
attribute: value;
}
</style>
CSS Selectors
- A selector is responsible for identifying any element in page and apply the given set of styles.
- The selectors are classified into various groups
1. Primary Selectors
2. Rational Selectors
3. Dynamic Pseudo classes
4. Structural Pseudo classes
5. Element State Pseudo classes
6. Element Validation State Pseudo classes
7. Universal Selector
8. Root Selector
9. Language Selector
10. Behavioural Selectors
Primary Selectors
1. Type Selector
2. ID Selector
3. Class Selector
Type Selector:
- It refers any HTML element by its "node" name.
<div> Element [Token]
div Node
- It will apply styles for every occurance in page.
- You can't ignore for any specific occurance in page.
Syntax:
h1 { img { td {
} } }
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../src/styles/[Link]">
<style>
h1
{
color:red;
background-color:yellow;
text-align:center;
}
</style>
</head>
<body>
<h1>Web Technologies</h1>
<h1>HTML</h1>
<h1>CSS</h1>
<h1>JavaScript</h1>
</body>
</html>
ID Selector:
- You can define styles using an ID reference.
- ID reference is configured using "#someId"
Syntax:
#id_ref
{
- You can apply effects to any specific element by accessing "id" reference.
Syntax:
<div id="id_ref"> </div>
- Every element in HTML can use the reference of only one ID.
- You can't apply styles form multiple ID references.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#text-style
{
text-align: center;
color:red;
}
#border-style
{
border:2px double red;
padding: 5px;
}
#back-style
{
background-color: yellow;
}
</style>
</head>
<body>
<h1 id="text-style">Web Technologies</h1>
<h1 id="border-style">HTML</h1>
<h1 id="back-style">CSS</h1>
<p>It defines styles for HTML.</p>
<h1>JavaScript</h1>
</body>
</html>
Class Selector:
- A class selector is configure using ".className".
- It is accessed by using the attribute "class".
Syntax:
.className
{
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.text-style
{
text-align: center;
color:red;
}
.border-style
{
border:2px double red;
padding: 5px;
}
.back-style
{
background-color: yellow;
}
</style>
</head>
<body>
<h1 class="text-style back-style border-style">Web Technologies</h1>
<h1 class="border-style text-style">HTML</h1>
<h1>CSS</h1>
<p>It defines styles for HTML.</p>
<h1>JavaScript</h1>
</body>
</html>
Rules
1. If any element is defined with type, id and class then which set will apply?
A.
- If different attributes are defined then all will apply.
- If same attribute is defined then the priority is used,
1st Id selector
2nd Class selector
3rd Type selector
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
h1 {
color:red;
border:3px double red;
}
#heading {
color:green;
}
.head-style {
color:blue;
background-color: yellow;
text-align: center;
}
</style>
</head>
<body>
<h1 class="head-style" id="heading" >Styles in HTML</h1>
</body>
</html>
2. You can group the selectors to apply effects for multiple elements. A group of selectors is defined
by separating them with ", "
Syntax:
h1, p {
font-family:"Arial";
}
h1, #para2 {
#para2, .p1 {
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
h1, #css, .html{
font-family: Arial;
}
</style>
</head>
<body>
<h1>Styles in HTML</h1>
<h2>Container Styles</h2>
<p id="css">CSS selectors for version 3.</p>
<p class="html">HTML version 5.</p>
</body>
</html>
Dynamic Pseudo Classes
- Dynamic allows to change the appearence of element according state and situation.
- Pseudo is a false appearence defined for element, It is a false representation for element.
- In computer programming class is a template.
- A template comprises of pre-defined data and logic, which you can implement and customize
according to requirement.
Sudhakar Sharma
Jul 6, 2023
CSS Selectors
1. Primary Selectors
Type
Id
Class
2. Dynamic Pseudo Classes
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
img {
width: 100px;
height: 100px;
transition: 5s;
}
img:active {
width: 200px;
height: 200px;
transition: 2s;
}
a:link {
text-decoration: none;
}
a:visited {
color:green;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<img src="../public/images/[Link]">
<p>
<a href="../public/[Link]">Amazon</a>
</p>
</body>
</html>
:read-only
:disabled
:checked
:focus
:blur [not available for all versions]
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#UserName:read-only {
cursor: not-allowed;
}
button:disabled {
border:goldenrod;
background-color: gold;
}
</style>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" id="UserName" value="John" readonly></dd>
</dl>
<button disabled>Submit</button>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#Terms+span {
color:red;
}
#Terms:checked+span {
color:green;
}
#Terms~button {
display: none;
}
#Terms:checked~button {
display: block;
}
#UserName+div {
display: none;
}
#UserName:focus+div {
display: block;
color:red;
}
</style>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" pattern="[A-Z]{4,10}" id="UserName"><div>Name in Block
Letters</div></dd>
<dt>Terms of Service</dt>
<dd>
<textarea rows="4" cols="40" disabled>License Aggrement</textarea>
</dd>
<dd>
<input type="checkbox" id="Terms"> <span>I Agree</span>
<br><br>
<button>Submit</button>
</dd>
</dl>
</body>
</html>
5. Rational Selectors
Child Selector parent child { } It set effects for all child elements
Direct Child Selector parent > child { } It sets only for direct child elements.
General Siblings A_Selector~B_Selector It sets effects for all elements after the
specified.
Ex-1:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container > p {
color:red;
}
</style>
</head>
<body>
<div class="container">
<p>Para-1</p>
<p>Para-2</p>
<div><p>Para-3</p></div>
<p>Para-4</p>
</div>
<p>Para-5</p>
</body>
</html>
Ex:
<style>
h2~p {
color:red;
}
</style>
<body>
<h2>heading</h2>
<p> Para-1 </p>
<p> Para-2 </p>
</body>
6. Attribute Selectors
element [ attribute = value ] { } It sets effects for all elements that match
the attribute value.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input[type="button"] {
background-color: yellow;
}
</style>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text"></dd>
<dt>Mobile</dt>
<dd><input type="text"></dd>
</dl>
<input type="button" value="Submit">
<input type="button" value="Cancel">
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
p[id]{
color:red;
}
</style>
</head>
<body>
<p>Para-1</p>
<p id="p2">Para-2</p>
<p>Para-3</p>
<p id="p4">Para-4</p>
</body>
</html>
EX:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
p[class~="Effect"] {
color:red;
}
</style>
</head>
<body>
<p class="Effect">Para-1</p>
<p class="ParaEffect">Para-2</p>
<p class="EffectPara">Para-3</p>
<p class="TextEffectPara">Para-4</p>
<p class="Effect-Para">Para-5</p>
<p class="Para-Effect">Para-6</p>
<p class="Effect Para">Para-7</p>
<p class="Para Effect">Para-8</p>
<p class="Text Effect Para">Para-9</p>
</body>
</html>
Syntax:
li : nth-child(4) {
::first-letter
::first-line
::selection
::before
::after
::placeholder
: Inheritance
: contract [interface]
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
p::first-letter {
font-size: 30px;
float: left;
}
p::first-line {
color:blue;
}
p::selection {
background-color: yellow;
}
</style>
</head>
<body>
<p>We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
p::first-letter {
font-size: 30px;
float: left;
}
p::first-line {
color:blue;
}
p::selection {
background-color: yellow;
}
input::placeholder {
color:green;
}
</style>
</head>
<body>
<input type="text" placeholder="Name min 4 chars">
<p>We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
ul {
list-style: none;
display: flex;
}
li::after {
content: " / ";
}
li:last-child::after {
content: "";
}
li:last-child {
color:gray;
}
</style>
</head>
<body>
<ul>
<li>Home</li>
<li>Electronics</li>
<li>Mobiles</li>
<li>Realme</li>
<li>C16</li>
</ul>
</body>
</html>
Sudhakar Sharma
Jul 7, 2023
9. Universal Selector
- It selects all elements in page.
*{
font-family:Arial;
}
:root {
font-family:Arial;
}
:lang(en) {
EX:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
:lang(en-us){
color:red;
}
</style>
</head>
<body>
<div lang="en-us">
<p>Hello ! World</p>
</div>
<div lang="en-fr">
<p>Bonjour! Monde</p>
</div>
<div lang="en-ger">
<p>Hallo! Welt</p>
</div>
</body>
</html>
CSS Rules
CSS Inheritance
- Inheritance is the mechanism where the styles of parent are adapted by child elements.
- The default inheritance will not apply all parent features to its child.
- You can define inheritance manually by using 3 attribute values
a) inherit
b) initial
c) unset
Syntax:
h2{
font-weight:unset;
}
h2 {
all:unset;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
border:3px dashed red;
font-family: Arial;
color:red;
padding: 20px;
}
h2{
border:inherit;
padding: inherit;
color:initial;
}
</style>
</head>
<body>
<div class="container">
<h2>Welcome to CSS</h2>
</div>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
border:3px dashed red;
font-family: Arial;
color:red;
padding: 20px;
}
h2{
all:inherit;
}
</style>
</head>
<body>
<div class="container">
<h2>Welcome to CSS</h2>
</div>
</body>
</html>
CSS Colors
1. Color Name
2. Color Shade Name
3. Hexa Decimal
4. rgb()
5. rgba()
6. hsl()
7. hsla()
8. Gradient
a) linear-gradient
b) radial-gradient
Color Name:
h2 {
color:red;
}
h2 {
color:lightyellow;
}
Hexa Decimal:
#RGB or #RRGGBB
R, G, B = 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f
h2 {
color:#f00;
}
h2 {
color:#ff0000
}
RGB Method:
- rgb() is a set of 3 colors which range value from 0 to 255.
rgba(255,0,0,0.5);
HSL Method:
- It configures "hue, saturation and lighting".
- Hue is an angle for colors from 0 to 360 deg.
- Saturation is "gray" percentage in color. [0 to 100%]
- Lighting is brightness from 0 to 100%
hue => 0 to 120 => Red, 120 to 240 => Green, 240 to 360 => Blue
sat => 0 % to 100%
light => 0% to 100%
Gradient Colors
- You can set gradient color only by using "background-image" attribute.
- CSS supports
a) linear-gradient [to various directions]
b) radial-gradient [to center]
Syntax:
{
background-image:linear-gradient(direction, color1, color2,...);
}
Ex
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
background-image: linear-gradient(to top right,red 50%, yellow, green);
height: 400px;
}
</style>
</head>
<body>
<div class="container">
<h2>Welcome to CSS</h2>
</div>
</body>
</html>
Ex:
<style>
body{
background-image: radial-gradient(red 10%, yellow, green);
height: 400px;
}
</style>
CSS Units
Absolute Units:
- They are individual with specified dimension, which is not effected by its parent.
- They have fixed size.
cm
mm
Q
in
pc
pt
px
Relative Units:
- They are configured based on the parent element.
- They change according to parent, they don't have fixed size.
- CSS relative units
em element size
rem root element size
% fluid - responsive [parent]
Syntax:
parent {
font-size: 20px;
}
child {
font-size: 0.5em;
}
child {
font-size: 0.5rem;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
font-size: 30px;
}
p{
font-size: 1.5rem;
}
</style>
</head>
<body>
Web Techologies
<div class="container">
Styles in HTML
<p>Welcome to styling pages.</p>
</div>
</body>
</html>
Summary
1. Integrating Styles into Page
2. CSS Selectors
3. CSS Rules
4. CSS Inheritance
5. CSS Colors
6. CSS Units
Sudhakar Sharma
•
Jul 8, 2023
syntax:
margin: top right bottom left;
margin: 10px 0px 10px 0px; [top & bottom]
margin-left
margin-right
margin-top
margin-bottom
2. Padding
Syntax:
padding:20px 0px 20px 0px;
3. Border
Syntax:
border: width style color;
border: 3px solid red;
<div class="container">
Styles in HTML
<p>Welcome to styling pages.</p>
</div>
</body>
</html>
Syntax:
{
border: 10px solid transparent;
border-image: url("path") style offset;
}
style => space, stretch
offset => 0 to 100
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
padding: 20px;
border: 10px solid transparent;
border-image: url("../public/images/[Link]") stretch 80;
}
</style>
</head>
<body>
<div class="container">
Styles in HTML
<p>Welcome to styling pages.</p>
</div>
</body>
</html>
4. Border Radius
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
img {
border-top-left-radius: 150px;
border-bottom-right-radius: 150px;
}
</style>
</head>
<body>
<img src="../public/images/[Link]" width="300" height="400">
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
ul {
display: flex;
list-style: none;
}
li {
background-color: black;
color:white;
font-family: Arial;
padding: 5px;
margin-right: 100px;
border-radius: 100px;
width:30px;
height: 30px;
font-size: 25px;
text-align: center;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<ul>
<li><span class="bi bi-cart4"></span></li>
<li><span class="bi bi-credit-card"></span></li>
<li>3</li>
<li>4</li>
</ul>
</body>
</html>
CSS Positions
1. Static
2. Absolute
3. Fixed
4. Relative
5. Sticky
Static:
- It keeps the element according to normal flow of document.
- You can't move the element by using left, top, right or bottom attributes.
- It have fixed location.
- It is the default position for element.
Absolute:
- It removes element from normal flow of document.
- You can move the element using left, right, top and bottom attributes.
- The element is fixed to the content in page not to browser.
- It moves along with content.
Fixed:
- It removes element from normal flow.
- You can move element using left, top, right, bottom
- It is attached to browser not to page.
- It will not move along with content.
- It is fixed in position.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.offer {
border:1px solid black;
background-color: yellow;
color:red;
width: 100px;
position: fixed;
top: 120px;
right: 20px;
}
.container {
border:2px solid black;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<div class="container">
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
Sticky
- It keeps element according to normal flow.
- It locks scrolling and fixed to browser after reaching specific position top, left, right or bottom.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.offer {
border:1px solid black;
background-color: yellow;
color:red;
width: 100px;
position: fixed;
top: 120px;
right: 20px;
}
.container {
border:2px solid black;
}
h1 {
position: sticky;
top: 0px;
}
.nav-container {
display: flex;
justify-content: space-around;
}
nav {
background-color: rgba(0,0,0,0.5);
color:white;
padding: 10px;
position: sticky;
top: 0px;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<div class="container">
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
<nav>
Quick Booking
<div class="nav-container">
<div>
<select>
<option>Select Movie</option>
</select>
</div>
<div>
<select>
<option>Select Cinema</option>
</select>
</div>
<div>
<select>
<option>Select Date</option>
</select>
</div>
<div>
<select>
<option>Select Time</option>
</select>
</div>
<div>
<select>
<option>Select Seats</option>
</select>
</div>
<div>
<button>Book</button>
</div>
</div>
</nav>
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
We understand that you may have questions about the Microsoft Services Agreement. We have
an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.
Relative:
- It is the position defined for parent element to keep the child elements with in the context of
parent.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#count {
position: absolute;
top:-10px;
right: -10px;
}
button {
position: relative;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h3>Shopping</h3>
<button class="btn btn-primary">
<span class="bi bi-cart4"></span> Your Cart
<span id="count" class="badge bg-danger rounded-circle">4</span>
</button>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.fashion {
width: 300px;
height: 400px;
background-image: url("../public/images/[Link]");
background-size: cover;
position: relative;
}
.save {
background-color: red;
color:white;
width: 70px;
height: 70px;
border-radius: 100px;
text-align: center;
font-size: 20px;
font-weight: bold;
position: absolute;
top: 10px;
right: 10px;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid mt-3">
<div class="fashion">
<div class="save">
<div><font size="3">Save</font></div>
<div>30%</div>
</div>
</div>
</body>
</html>
Sudhakar Sharma
CSS Positions
- Static
- Absolute
- Fixed
- Sticky
- Relative
CSS Z-Index
- It is used to place element
a) front
b) forward
c) back
d) backward
- If elements are overlapping then you can change the placement order by using
"z-index".
- It is a number starts with 0 = back
Syntax:
div {
z-index: 0;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Z-Index</title>
<style>
div {
width: 300px;
height: 200px;
border:2px solid black;
position: absolute;
}
.card-red {
background-color: red;
margin-left: 20px;
margin-top: 20px;
z-index: 2;
}
.card-blue {
background-color: blue;
margin-left: 40px;
margin-top: 40px;
z-index: 1;
}
.card-yellow {
background-color: yellow;
margin-left: -60px;
margin-top: 60px;
z-index: 0;
}
</style>
</head>
<body>
<div class="card-red">
</div>
<div class="card-blue">
</div>
<div class="card-yellow">
</div>
</body>
</html>
CSS Display
1. none
2. block
3. inline
4. inline-block
5. flex
6. grid
display:none
- It is used to hide element on page.
- It removes the allocated space for element in page.
visitibilty:hidden will hide element but keeps the space allocated for element on
page.
Syntax:
h1 {
visibility:hidden;
}
h1 {
display:none;
}
display:inline
- It is used to keep elements side by side.
- It is defined for element directly.
FAQ: What is difference between inline and flex?
Ans: Inline is defined for element individually.
flex is defined for container that contains elements.
Syntax:
ul {
display: inline; => invalid
}
li {
display: inline; => valid
}
Inline-Block
- Inline content can't change their width and height.
- <span> is default inline and you can't control its width and height.
- To change the width and height of inline content, you can set "inline-block".
Syntax:
nav span {
width:100px; => width & height are not applied
height:20px;
border:1px solid black;
}
nav span {
width:100px; => It can set width and height
height:20px;
border:1px solid black;
display:inine-block;
}
Display Block
- It can arrange inline elements into columns.
Syntax:
nav span {
display:block;
width:100px;
height:30px;
border:1px solid black;
}
Display Grid
- It is used for creating responsive layout.
- It allows to change the position of content dynamically with media queries.
- Display Grid styles provides various attributes
grid-template-columns
grid-row
grid-column
grid-gap
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Layout</title>
<style>
header, nav, main, aside, footer {
border:1px solid black;
margin: 5px;
padding: 10px;
}
@media screen and (orientation:landscape){
body {
display: grid;
grid-template-columns: 2fr 8fr 2fr;
}
header {
grid-row: 1;
grid-column: 1/4;
}
nav {
grid-row: 2;
grid-column: 1;
}
main {
grid-row: 2;
grid-column: 2;
height: 400px;
background-image: url("../public/images/[Link]");
background-size: cover;
}
aside {
grid-row: 2;
grid-column: 3;
}
footer {
grid-row: 3;
grid-column: 1/4;
}
}
@media screen and (orientation:portrait) {
body{
display: grid;
grid-template-columns: 12fr;
}
header {
grid-row: 1;
position: relative;
}
nav {
grid-row: 1;
width: 50px;
position: absolute;
right: 10px;
background-color: black;
color:White;
}
main {
grid-row: 3;
height: 400px;
background-image: url("../public/images/[Link]");
background-size: cover;
}
aside {
grid-row: 4;
display: none;
}
footer {
grid-row: 5;
}
}
</style>
</head>
<body>
<header>
Header
</header>
<nav>
Nav
</nav>
<main>
Main
</main>
<aside>
Aside
</aside>
<footer>
Footer
</footer>
</body>
</html>
Sudhakar Sharma
Display Grid
Syntax:
body {
display : grid;
grid-template-columns: 6fr 6fr;
grid-gap: 20px;
}
header{
grid-row : 1; It starts and ends at 1.
}
header {
grid-column: 1; It starts and ends at 1.
}
header {
grid-column: 1/4; It starts at 1 and ends at 3.
}
"columns" will add connected columns, the content of one column will span to
next.
Columns
Syntax:
body {
columns : 5;
column-gap: 20px;
column-rule: 2px dotted black;
}
.container {
column-span: all;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>News</title>
<style>
header {
font-size: 40px;
background-color: black;
color:white;
font-weight: bold;
text-align: center;
padding: 5px;
}
section {
columns:5;
column-gap: 20px;
column-rule: 2px dotted black;
margin-top: 20px;
text-align: justify;
}
.banner {
column-span: all;
}
</style>
</head>
<body>
<header>
THE HINDU
</header>
<section>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<div class="banner">
<img src="../public/images/[Link]" width="100%">
</div>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
</section>
</body>
</html>
Display Flex
- It is used for container that contains elements to display in page.
- It can set orientation for content in container, which includes
flex-row
flex-row-reverse
flex-column
flex-column-reverse
- It can control the wrapping
flex-wrap
flex-norwap
- It can control the space between elements
justify-space-between
justify-space-evenly
justify-space-around
justify-flex-start
justify-flex-end
center
Syntax:
.container {
display:flex;
flex-direction: row | row-reverse ...;
flex-wrap: nowrap | wrap;
justify-content: space-between, ...;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flex</title>
<style>
nav div {
width: 100px;
height: 30px;
border:2px solid black;
margin: 5px;
text-align: center;
background-color: yellow;
}
@media screen and (orientation:landscape) {
nav {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
border:2px solid black;
padding: 10px;
}
}
@media screen and (orientation:portrait) {
nav {
display: flex;
flex-direction: column;
justify-content: space-between;
border:2px solid black;
padding: 10px;
width: 100px;
height: 400px;
}
.nav-item {
display: none;
}
nav div {
border-radius: 30px;
width: 40px;
font-size: 30px;
padding: 5px;
}
nav div:hover .nav-item {
display: inline;
}
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<nav>
<div> <span class="bi bi-house"></span> <span class="nav-item">Home</span></div>
<div> <span class="bi bi-cart3"></span> <span class="nav-item">Shop</span></div>
<div> <span class="bi bi-bell"></span> <span class="nav-item">Contact</span> </div>
<div> <span class="bi bi-twitter"></span> <span class="nav-item">Blog</span></div>
</nav>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Center</title>
<style>
img {
border-radius: 200px;
height: 300px;
width: 300px;
}
body {
display: flex;
justify-content: center;
text-align: center;
align-items: center;
height: 600px;
}
</style>
</head>
<body>
<div>
<img src="../public/images/[Link]">
<p>Offer 50% OFF</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopper</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
header {
display: flex;
justify-content: space-between;
font-size: 20px;
font-family: Arial;
padding: 15px;
}
span{
margin-right: 20px;
}
.brand-name {
font-size: 30px;
font-weight: bold;
}
article {
background-color: black;
color:white;
font-size: 16px;
padding: 10px;
text-align: center;
margin-top: 10px;
font-family: Arial;
}
.bi-lightning-fill {
color:gold;
}
section{
margin-top: 5px;
margin-bottom: 50px;
}
footer {
background-color: black;
color:white;
font-size: 15px;
font-family: Arial;
padding: 10px;
display: grid;
grid-template-columns: 2.4fr 2.4fr 2.4fr 2.4fr 2.4fr;
}
.footer-brand-name {
font-size: 30px;
font-weight: bold;
margin-bottom: 20px;
}
.title {
font-weight: bold;
margin-bottom: 20px;
}
.title~div {
margin-bottom: 15px;
}
main div {
opacity: 0.6;
}
main div:hover {
opacity: 1;
}
.women {
background-image: url("images/[Link]");
background-size: cover;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
height: 500px;
font-size: 40px;
color:white;
}
.men {
background-image: url("images/[Link]");
text-align: center;
display: flex;
justify-content: center;
align-items: center;
height: 500px;
font-size: 40px;
color:white;
background-size: cover;
}
.kids {
background-image: url("images/[Link]");
text-align: center;
display: flex;
justify-content: center;
align-items: center;
height: 500px;
font-size: 40px;
color:white;
background-size: cover;
}
main {
display: grid;
grid-template-columns: 4fr 4fr 4fr;
grid-gap: 5px;
}
h1 {
text-shadow: 2px 2px 2px black;
}
button {
width: 200px;
height: 40px;
font-size: 20px;
}
</style>
</head>
<body>
<header>
<div>
<span class="brand-name">Shopper.</span>
</div>
<div>
<nav>
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Pages</span>
<span>Blog</span>
<span>Docs</span>
</nav>
</div>
<div>
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart4"></span>
</div>
</header>
<article>
<span class="bi bi-lightning-fill"></span>HAPPY HOLIDAY DEALS ON EVERYTHING <span class="bi
bi-lightning-fill"></span>
</article>
<section>
<main>
<div class="women">
<div>
<h1>Women</h1>
<button>Shop Women <span class="bi bi-arrow-right"></span> </button>
</div>
</div>
<div class="men">
<div>
<h1>Men</h1>
<button>Shop Men <span class="bi bi-arrow-right"></span> </button>
</div>
</div>
<div class="kids">
<div>
<h1>Kids</h1>
<button>Shop Kids <span class="bi bi-arrow-right"></span> </button>
</div>
</div>
</main>
</section>
<footer>
<div>
<div class="footer-brand-name">
<span>Shopper.</span>
</div>
<div>
<span class="bi bi-facebook"></span>
<span class="bi bi-twitter"></span>
<span class="bi bi-instagram"></span>
<span class="bi bi-youtube"></span>
</div>
</div>
<div>
<div class="title">SUPPORT</div>
<div>Contact Us</div>
<div>FAQs</div>
<div>Size Guide</div>
<div>Shipping & Returns</div>
</div>
<div>
<div class="title">SHOP</div>
<div>Men's Shopping</div>
<div>Women's Shopping</div>
<div>Kids' Shopping</div>
<div>Discounts</div>
</div>
<div>
<div class="title">COMPANY</div>
<div>Our Story</div>
<div>Careers</div>
<div>Terms & Conditions</div>
<div>Privacy & Cookie policy</div>
</div>
<div>
<div class="title">CONTACT</div>
<address>
<div>1-202-555-0105</div>
<div>1-202-555-0106</div>
<div>help@[Link]</div>
</address>
</div>
</footer>
</body>
</html>
Sudhakar Sharma
Horizontal Line:
<hr size="" width="" noshade color="">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopper</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
header {
display: flex;
justify-content: space-between;
font-size: 20px;
font-family: Arial;
padding: 15px;
}
span{
margin-right: 20px;
}
.brand-name {
font-size: 30px;
font-weight: bold;
}
article {
background-color: black;
color:white;
font-size: 16px;
padding: 10px;
text-align: center;
margin-top: 10px;
font-family: Arial;
}
.bi-lightning-fill {
color:gold;
}
section{
margin-top: 5px;
margin-bottom: 50px;
}
footer {
background-color: black;
color:white;
font-size: 15px;
font-family: Arial;
padding: 10px;
display: grid;
grid-template-columns: 2.4fr 2.4fr 2.4fr 2.4fr 2.4fr;
}
.footer-brand-name {
font-size: 30px;
font-weight: bold;
margin-bottom: 20px;
}
.title {
font-weight: bold;
margin-bottom: 20px;
}
.title~div {
margin-bottom: 15px;
}
main div {
opacity: 0.6;
}
main div:hover {
opacity: 1;
}
.women {
background-image: url("images/[Link]");
background-size: cover;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
height: 500px;
font-size: 40px;
color:white;
}
.men {
background-image: url("images/[Link]");
text-align: center;
display: flex;
justify-content: center;
align-items: center;
height: 500px;
font-size: 40px;
color:white;
background-size: cover;
}
.kids {
background-image: url("images/[Link]");
text-align: center;
display: flex;
justify-content: center;
align-items: center;
height: 500px;
font-size: 40px;
color:white;
background-size: cover;
}
main {
display: grid;
grid-template-columns: 4fr 4fr 4fr;
grid-gap: 5px;
}
h1 {
text-shadow: 2px 2px 2px black;
}
button {
width: 200px;
height: 40px;
font-size: 20px;
}
.site-features {
margin-top: 20px;
display: grid;
grid-template-columns: 3fr 3fr 3fr 3fr;
margin-bottom: 50px;
}
.bi-truck, .bi-arrow-left-right, .bi-tag, .bi-bag {
color : red;
}
.feature-text {
font-family: Arial;
color:gray;
margin-left: 35px;
margin-top: 10px;
}
.site-highlights {
display: flex;
justify-content: center;
align-items: center;
height: 300px;
text-align: center;
font-family: Arial;
}
.sh-title {
font-size: 35px;
font-weight: bold;
margin-top: 20px;
}
.sh-subtitle {
color:gray;
font-weight: bold;
}
.sh-text {
font-size: 18px;
width: 600px;
line-height: 30px;
}
.site-banner-1 {
display: grid;
grid-template-columns: 4fr 8fr;
grid-gap: 50px;
height: 500px;
}
.women-bag {
background-image: url("images/[Link]");
background-size: cover;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.men-shirt {
background-image: url("images/[Link]");
background-size: cover;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
position: relative;
}
.site-banner-container {
margin-left: 100px;
margin-right: 100px;
}
.wb-title {
font-size: 35px;
color:white;
font-family: Arial;
font-weight: bold;
text-shadow: 2px 2px 2px black;
}
.wb-subtitle {
font-size: 25px;
color:white;
margin-top: 20px;
}
.men-title {
font-size: 35px;
font-family: Arial;
font-weight: bold;
text-shadow: 2px 2px 2px black;
color:white;
}
.men-subtitle {
font-size: 25px;
margin-top: 20px;
width: 200px;
color:white;
}
.offer {
font-size: 20px;
font-family: Arial;
font-weight: bold;
text-align: center;
background-color: red;
color:white;
width: 70px;
height: 60px;
border-radius: 50px;
padding: 5px;
position: absolute;
top: 15px;
left: 15px;
}
</style>
</head>
<body>
<header>
<div>
<span class="brand-name">Shopper.</span>
</div>
<div>
<nav>
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Pages</span>
<span>Blog</span>
<span>Docs</span>
</nav>
</div>
<div>
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart4"></span>
</div>
</header>
<article>
<span class="bi bi-lightning-fill"></span>HAPPY HOLIDAY DEALS ON EVERYTHING <span class="bi
bi-lightning-fill"></span>
</article>
<section>
<!-- Main Section Starts with 3 cards -->
<main>
<div class="women">
<div>
<h1>Women</h1>
<button>Shop Women <span class="bi bi-arrow-right"></span> </button>
</div>
</div>
<div class="men">
<div>
<h1>Men</h1>
<button>Shop Men <span class="bi bi-arrow-right"></span> </button>
</div>
</div>
<div class="kids">
<div>
<h1>Kids</h1>
<button>Shop Kids <span class="bi bi-arrow-right"></span> </button>
</div>
</div>
</main>
<div class="site-features">
<div>
<div>
<span class="bi bi-truck"></span> <span>FREE SHIPPING</span>
</div>
<div class="feature-text">
From all orders over $100
</div>
</div>
<div>
<div>
<span class="bi bi-arrow-left-right"></span> <span>FREE RETURNS</span>
</div>
<div class="feature-text">
Return money within 30 days
</div>
</div>
<div>
<div>
<span class="bi bi-bag"></span> <span>SECURE SHOPPING</span>
</div>
<div class="feature-text">
You're in safe hands
</div>
</div>
<div>
<div>
<span class="bi bi-tag"></span> <span>OVER 10,000 STYLES</span>
</div>
<div class="feature-text">
We have everything you need
</div>
</div>
</div>
<!--Horizontal Line-->
<hr size="2" noshade width="80%">
<div class="site-highlights">
<div>
<div class="sh-subtitle">NEW COLLECTION</div>
<div class="sh-title">Best Picks 2019</div>
<p class="sh-text">Appear, dry there darkness they're seas, dry waters thing fly midst. Beast,
above fly brought Very green.</p>
</div>
</div>
<!--Site Banners-->
<div class="site-banner-container">
<div class="site-banner-1">
<div class="women-bag">
<div>
<div class="wb-title">Bags Collection</div>
<div class="wb-subtitle">Shop Now <span class="bi bi-arrow-right"></span></div>
</div>
</div>
<div class="men-shirt">
<div class="offer">
<div>Save</div>
<div>30%</div>
</div>
<div>
<div class="men-title">Shirts Collection</div>
<div class="men-subtitle">Shop Now <span class="bi bi-arrow-right"></span></div>
</div>
</div>
</div>
</div>
</section>
<footer>
<div>
<div class="footer-brand-name">
<span>Shopper.</span>
</div>
<div>
<span class="bi bi-facebook"></span>
<span class="bi bi-twitter"></span>
<span class="bi bi-instagram"></span>
<span class="bi bi-youtube"></span>
</div>
</div>
<div>
<div class="title">SUPPORT</div>
<div>Contact Us</div>
<div>FAQs</div>
<div>Size Guide</div>
<div>Shipping & Returns</div>
</div>
<div>
<div class="title">SHOP</div>
<div>Men's Shopping</div>
<div>Women's Shopping</div>
<div>Kids' Shopping</div>
<div>Discounts</div>
</div>
<div>
<div class="title">COMPANY</div>
<div>Our Story</div>
<div>Careers</div>
<div>Terms & Conditions</div>
<div>Privacy & Cookie policy</div>
</div>
<div>
<div class="title">CONTACT</div>
<address>
<div>1-202-555-0105</div>
<div>1-202-555-0106</div>
<div>help@[Link]</div>
</address>
</div>
</footer>
</body>
</html>
CSS Float
- It keeps the content in page floating left or right.
Syntax:
{
float : left | right ;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.title {
font-size: 60px;
font-family: Arial;
color:darkcyan;
}
.sub-title {
font-size: 22px;
font-family: Arial;
width: 600px;
line-height: 40px;
}
.banner-img {
float: right;
}
.banner-text {
margin-left: 100px;
}
.btn-view {
background-color: lightcyan;
font-size: 20px;
padding: 20px;
border:none;
}
.btn-doc {
background-color: gray;
font-size: 20px;
padding: 20px;
border:none;
color:White;
}
</style>
</head>
<body>
<main>
<img class="banner-img" src="../public/images/[Link]" width="600" height="400">
<div class="banner-text">
<div class="title">
Welcome to Landkit.<br>
Develop anything.
</div>
<p class="sub-title">
Build a beautiful, modern website with flexible Bootstrap components built from scratch.
</p>
<button class="btn-view">View All Pages</button>
<button class="btn-doc">Documentation</button>
</div>
</main>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
h1 {
float: left;
}
h2 {
float: right;
}
p{
clear: both;
}
</style>
</head>
<body>
<h1>Title</h1>
<h2>Subtitle</h2>
<p>Some text</p>
</body>
</html>
Sudhakar Sharma
•
Jul 13, 2023
CSS Background
background-image
background-color
background-size
background-position
background-repeat
background-attachment
Ex:
body {
background-image: url("../public/images/[Link]");
background-repeat: no-repeat;
background-position: center center;
background-size: 300px 200px;
background-attachment: fixed;
height: 100vh;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
body {
background-image: url("../public/images/[Link]"), url("../public/images/[Link]");
background-repeat: no-repeat, repeat;
background-size: 200px 200px, 200px 200px;
background-position: center center;
height: 100vh;
}
</style>
</head>
<body>
</body>
</html>
CSS Lists
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
ol {
list-style-image: url("../public/images/[Link]");
font-size: 30px;
list-style-position: inside;
}
li {
border:3px solid black;
margin-bottom: 10px;
}
</style>
</head>
<body>
<ol>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ol>
</body>
</html>
Syntax:
{
text-decoration: underline 2px wavy red; [set none to remove all]
}
Syntax:
p{
white-space: nowrap;
border:1px solid black;
width:300px;
text-overflow: ellipses;
overflow: hidden;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
p{
border: 1px solid black;
width: 340px;
white-space: nowrap;
padding: 2px;
overflow: hidden;
word-wrap: break-word;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<p title="We understand that you may have questions about the Microsoft Services Agreement.
We have an FAQ page ([Link]
that provides more information, including what Microsoft products and services it covers. Whenever
we make changes, we provide a summary of the most notable changes to the current Microsoft
Services Agreement. We will also continue to provide a summary of the changes to the previous
version, and a link to the previous version, of the Microsoft Services Agreement on the Summary of
Changes ([Link] page.">We
understand that you may have questions about the Microsoft Services Agreement. We have an FAQ
page ([Link] that provides more
information, including what Microsoft products and services it covers. Whenever we make changes,
we provide a summary of the most notable changes to the current Microsoft Services Agreement.
We will also continue to provide a summary of the changes to the previous version, and a link to the
previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
</body>
</html>
CSS Transforms
- Transform is the process of changing from one state to another.
- CSS have 2 types of transforms
a) 2D Transforms
b) 3D Transforms
2D Transforms:
- It refers to transformation on 2 dimensions.
X
Y
- CSS Transforms support changing the position, size and orientation of element.
- CSS 2D Transforms are handled by using following methods
translate()
scale()
rotate()
skew()
matrix()
Note: CSS Transforms are not compatible to various browsers. You have to use
additional plugins.
{
transform : scale();
-webkit-transform: scale();
-moz-transform: scale();
-o-transform: scale();
-ms-transform: scale();
}
translate()
- It is a method used to change the position of element along X & Y axis.
translate()
translateX()
translateY()
Syntax:
img {
transform: translate(200px, 50px); x = 200, y = 50
}
img {
transform: translateX(200);
transform: translateY(100);
}
scale()
- It is used to change the size of element.
Syntax:
img {
transform: scale(2, 1);
}
img {
transform: scaleX(2);
transform: scaleY(2);
}
skew()
- It is used to tilt your element by specified angle.
Syntax:
img {
transform: skew(-20deg, 20deg);
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
img:hover {
transform: skew(-20deg, 20deg);
transition: 2s;
}
img {
transition: 2s;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
</style>
</head>
<body>
<img src="../public/images/[Link]" width="200" height="200">
</body>
</html>
rotate()
- It rotates element by specified angle.
rotate()
rotateX()
rotateY()
Syntax:
img {
transform: rotate(360deg);
}
Ex
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
img:hover {
transform: rotate(-360deg);
transition: 2s;
}
img {
transition: 2s;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
</style>
</head>
<body>
<img src="../public/images/[Link]" width="200" height="200">
</body>
</html>
Sudhakar Sharma
CSS 2D Transforms
translate()
scale()
skew()
rotate()
matrix()
- It configures multiple transforms.
Syntax:
matrix(scaleX(), skewX(), skewY(), scaleY(), translateX(), translateY())
Ex:
matrix(1.5,0.2, 0.2, 2, 50, 50);
CSS 3D Transforms
- It can transform elements in 3 Dimensions.
X, Y, Z
- Methods
translate3D()
scale3D()
skew3D()
roate3D()
matrix3D()
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
img:hover {
transform: scale3d(1.5,1.5,2.5);
transition: 2s;
box-shadow: 14px 14px 2px black;
}
img {
transition: 2s;
margin-right: 50px;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
</style>
</head>
<body>
<div>
<img src="../public/images/[Link]" width="200" height="200">
<img src="../public/images/[Link]" width="200" height="200">
<img src="../public/images/[Link]" width="200" height="200">
</div>
</body>
</html>
CSS Transitions
- Transition is used to control the transforms with timing and orentations.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
div {
width: 100px;
height: 50px;
background-color: red;
transition-duration: 5s;
transition-delay: 1s;
transition-timing-function: steps(10);
}
div:hover {
width: 100%;
transition-duration: 3s;
transition-delay: 1s;
transition-property: width;
transition-timing-function: steps(4);
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>
Syntax:
@keyframes Name
{
from { initial state
}
to { final state
}
}
Syntax:
@keyframes Name
{
from {
}
5% {
}
10% {
}
90%{
}
to {
}
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
@keyframes Blink
{
from {
opacity: 0;
}
50% {
transform: rotate(360deg);
}
to {
opacity: 1;
}
}
img {
animation-name: Blink;
animation-duration: 1s;
animation-iteration-count: infinite;
}
</style>
</head>
<body>
<img src="../public/images/[Link]" width="150" height="150">
</body>
</html>
Sudhakar Sharma
Syntax:
@keyframes name
{
from {
}
break-point {
}
to {
}
}
animation-name
animation-duration
animation-delay
animation-timing-function
animation-iteration-count
animation-direction
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Backgrounds</title>
<style>
@keyframes zoom {
from {
margin-left: 140%;
margin-top: -40px;
width: 50px;
height: 60px;
}
25% {
transform: rotate(180deg);
}
50% {
margin-top: 200px;
width: 300px;
height: 400px;
}
75% {
transform: rotate(360deg);
}
to {
margin-left: -80px;
margin-top: -80px;
width: 50px;
height: 60px;
}
}
img {
animation-name: zoom;
animation-duration: 5s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
body {
overflow: hidden;
}
</style>
</head>
<body>
<img src="../public/images/[Link]" width="50" height="60">
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.fashion {
width: 300px;
height: 400px;
overflow: hidden;
}
img {
width: 340px;
height: 440px;
transition-duration: 1s;
}
img:hover {
transform: translateX(-20px);
transition-duration: 1s;
}
</style>
</head>
<body>
<div class="fashion">
<img src="../public/images/[Link]">
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.fashion {
width: 300px;
height: 400px;
background-image: url("../public/images/[Link]");
background-size: cover;
display: flex;
justify-content: center;
padding-bottom: 20px;
overflow: hidden;
}
.fashion:hover {
background-image: url("../public/images/[Link]");
}
.icons span {
font-size: 22px;
background-color: darkcyan;
color:white;
padding: 5px;
border-radius: 40px;
margin-right: 10px;
}
.fashion:hover .icons {
margin-top: 380px;
transition: 2s;
}
.fashion .icons {
margin-top: 430px;
transition: 1s;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<div class="fashion">
<div class="icons">
<span class="bi bi-heart-fill"></span>
<span class="bi bi-cart3"></span>
<span class="bi bi-share"></span>
</div>
</div>
</body>
</html>
Ex: Delay
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
}
@keyframes zoom {
from {
font-size: 10px;
}
to {
font-size: 150px;
}
}
.w {
animation-name: zoom;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
.es {
animation-name: zoom;
animation-duration: 1s;
animation-delay: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
}
div span {
margin-left: 40px;
}
div {
width: 700px;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<div>
<span class="w">W</span>
<span class="es">E</span>
<span class="l">L</span>
<span class="c">C</span>
<span class="o">O</span>
<span class="m">M</span>
<span class="e">E</span>
</div>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
}
span {
font-size: 150px;
}
@keyframes colorwave {
from {
color:red;
}
to {
color: black;
}
}
.w {
animation-name: colorwave;
animation-duration: 1s;
animation-direction: alternate;
}
.es {
animation-name: colorwave;
animation-duration: 1s;
animation-delay: 2s;
animation-direction: alternate;
}
.l {
animation-name: colorwave;
animation-duration: 1s;
animation-delay: 3s;
animation-direction: alternate;
}
.c {
animation-name: colorwave;
animation-duration: 1s;
animation-delay: 4s;
animation-direction: alternate;
}
.o {
animation-name: colorwave;
animation-duration: 1s;
animation-delay: 5s;
animation-direction: alternate;
}
.m {
animation-name: colorwave;
animation-duration: 1s;
animation-delay: 6s;
animation-direction: alternate;
}
</style>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<div>
<span class="w">W</span>
<span class="es">E</span>
<span class="l">L</span>
<span class="c">C</span>
<span class="o">O</span>
<span class="m">M</span>
<span class="e">E</span>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.carousel {
display: flex;
overflow: hidden;
}
@keyframes slide1 {
from {
margin-left: 200%;
}
50% {
margin-left: 0%;
}
to {
margin-left: -200%;
}
}
@keyframes slide2 {
from {
margin-left: 200%;
}
50% {
margin-left: 0%;
}
to {
margin-left: 0%;
}
}
.slide1 {
animation-name: slide1;
animation-duration: 2s;
}
.slide2 {
animation-name: slide2;
animation-duration: 2s;
animation-delay: 5s;
}
</style>
</head>
<body>
<div class="carousel">
<img class="slide1" src="../public/images/[Link]" width="100%">
<img class="slide2" src="../public/images/[Link]" width="100%">
</div>
</body>
</html>
Media Queries
Media Queries
Sudhakar Sharma
1. Meta Viewport
<img width="100%">
<table width="100%">
4. Media Queries
- A media query identifies the type of media device, orientation and dimensions.
Syntax:
@media mediaType (query)
{
2. min-width : It defines the units starting with specified point upto end.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Media Demo</title>
<style>
ul {
list-style: none;
}
li {
width: 140px;
padding: 5px;
border:1px solid black;
margin: 5px;
}
@media screen and (min-width:800px){
ul {
display: flex;
justify-content: space-around;
}
}
</style>
</head>
<body>
<ul>
<li>Home</li>
<li>Shop</li>
<li>Pages</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</body>
</html>
4. Orientation : It identifies the device orientation and sets the content in page
in landscape or portrait mode.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Media Demo</title>
<style>
ul {
list-style: none;
}
li {
width: 140px;
padding: 5px;
border:1px solid black;
margin: 5px;
}
@media screen and (orientation:landscape){
ul {
display: flex;
justify-content: space-around;
}
}
</style>
</head>
<body>
<ul>
<li>Home</li>
<li>Shop</li>
<li>Pages</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Media Demo</title>
<style>
ul {
list-style: none;
}
li {
width: 140px;
padding: 5px;
border:1px solid black;
margin: 5px;
}
@media screen and (orientation:landscape) and (min-width:600px){
ul {
display: flex;
justify-content: space-around;
}
}
</style>
</head>
<body>
<ul>
<li>Home</li>
<li>Shop</li>
<li>Pages</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</body>
</html>
Component Libraries
- It is a library of HTML, CSS and JavaScript components that allow developers to design faster with
simiplified approach.
- There are various component libraries for UI designing
a) Bootstrap
b) Twitter Bootstrap
c) Telerik
d) DevExpress
e) Material UI etc..
Bootstrap
- It is a component library for building simple and rich UI for web.
- It makes UI design faster.
- The latest version of bootstrap is "5x".
Bootstrap
Sudhakar Sharma
Bootstrap
- It is a component library.
- It make UI designing easy and faster.
- It is open source and cross platform library.
- Open source allows to customize the library according to requirements.
- Cross platform makes the library available to all devices and OS services.
- Component is a template which you can re-use and customize.
- A component is built with
a) HTML [Presentation]
b) Styles [CSS]
c) Logic [jQuery]
Note: To view the components hierarchy in HTML page, you can select the option
"Show user agent shadow DOM"
in Debugger settings.
- The latest version of bootstrap is "5x".
- To setup bootstrap in project you have to install following
[Link]
[Link]
[Link] [node_modules/bootstrap/dist/js]
[Link] [node_modules/jquery/dist]
[Link] [optional]
Note: CSS files have no order dependency. But javascript file have order dependency.
[Link]
[Link]
- Bootstrap provides CSS classes & jQuery attributes, which are used to design components.
.m-{size} 1 to 4
.ms-{size}
2. Padding
.p short hand
.ps
.pe
.pt
.pb
.p-{size} 1 to 4
3. Border
.border
.border-{contextual} primary, danger, warning, info, success, dark
.border-{size} 1 to 3
4. Border Radius
.rounded
.rounded-{size} 1 to 3
.rounded-circle
.rounded-pill
5. Width
.w-{size} 25, 50, 100
6. Height
.h-{size} 25, 50, 100
Bootstrap Display
.d-flex
.flex-wrap
.flex-row
.flex-row-reverse
.flex-col
.flex-col-reverse
.justify-content-between
.justify-content-evenly ...
.align-items-center
.align-items-end
.align-items-start
.d-none
.d-block
.d-inline
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="d-flex text-center justify-content-center align-items-center" style="height: 100vh;">
<div class="border border-2 border-primary mt-2 ps-2 rounded w-50">
<h1>Welcome to Bootstrap</h1>
<p>Component library - Build rich UI</p>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Bootstrap Grid
.row
.col fluid
.col-{size} 1 to 12
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h3>Product Details</h3>
<dl class="row">
<dt class="col-2">Name</dt>
<dd class="col-10">Samsung TV</dd>
<dt class="col-2">Price</dt>
<dd class="col-10">46000.44</dd>
<dt class="col-2">Stock</dt>
<dd class="col-10">Available</dd>
</dl>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h1>Personal Loan EMI Calculator</h1>
<div class="border border-dark p-4 bg-success text-white">
<div class="row">
<div class="col">
Amount you need ₹ <input type="text">
</div>
<div class="col">
for <input type="text" size="4"> years
</div>
<div class="col">
Interest Rate <input type="text" size="4"> %
</div>
</div>
<div class="row mt-4">
<div class="col">
<input type="range" min="1" max="100" value="1" class="form-range">
</div>
<div class="col">
<input type="range" class="form-range">
</div>
<div class="col">
<input type="range" class="form-range">
</div>
</div>
<div class="row">
<div class="col">
<p class="float-start">₹ 10,000</p>
<p class="float-end">₹ 10,00,000</p>
</div>
<div class="col">
<p class="float-start">1</p>
<p class="float-end">5</p>
</div>
<div class="col">
<p class="float-start">8.45 %</p>
<p class="float-end">10.45 %</p>
</div>
</div>
<div class="row mt-4">
<div class="col">
<button class="btn btn-warning float-end">Calculate</button>
</div>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Bootstrap Positions
.position-absolute
.position-fixed
.position-static
.position-relative
.position-sticky
.top-{0,50,100}
.bottom
.end
.start
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<aside class="position-fixed bottom-0 end-0">
<div class="bi bi-facebook"></div>
<div class="bi bi-twitter"></div>
<div class="bi bi-instagram"></div>
</aside>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h2>Shopping</h2>
<button class="btn btn-dark position-relative">
Your Cart
<span class="bi bi-cart4"></span>
<span class="badge bg-danger rounded rounded-circle position-absolute top-0 end-0">2</span>
</button>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Bootstrap Components
Sudhakar Sharma
Text Classes
.text-{contextual} primary, secondary, danger, warning...
.text-{align} start, end, center, justify
.text-{case} uppercase, lowercase, capitalize
.fw font-weight, bold
.fst font-style, italics
.text-decoration-{} none, underline, overline
Background Classes
.bg-{contextual}
Bootstrap Components
1. Alerts
- Embeded message boxes in page.
- You can control dynamically.
Classes:
.alert
.alert-{contextual}
.alert-title
.alert-text
.alert-link
.alert-dismissible
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h2>Alerts</h2>
<div class="alert alert-danger alert-dismissible">
<button class="btn-close" data-bs-dismiss="alert"></button>
<h1 class="alert-title">Delete Record</h1>
<p class="alert-text">Record will be delete permanently..</p>
<a class="alert-link" href="#">Help?</a>
</div>
<div class="alert alert-success alert-dismissible">
<h1>Record Inserted</h1>
<p>Record successfully inserted into database.</p>
<button data-bs-dismiss="alert" class="btn btn-success">OK</button>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
2. Modals
- It can create pop-up dialog boxes in page.
Classes:
.modal
.modal-dialog
.modal-dialog-centered
.modal-fullscreen
.modal-dialog-scrollable
.modal-content
.modal-header
.modal-body
.modal-footer
.fade
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="mt-3">
<button data-bs-toggle="modal" data-bs-target="#login" class="btn
btn-primary">Login</button>
<button data-bs-toggle="modal" data-bs-target="#details" class="btn btn-info">Product
Details</button>
</div>
<div class="modal fade" id="details">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3>Realme Mobile</h3>
<button class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<dl>
<dt>Name</dt>
<dd>Realme C16</dd>
<dt>Preview</dt>
<dd>
<img src="../public/images/[Link]" width="200" height="300">
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="modal fade" id="login">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header text-white">
<h3> <span class="bi bi-person-fill"></span> User Login</h3>
<button data-bs-dismiss="modal" class="btn-close"></button>
</div>
<div class="modal-body">
<dl>
<dt>User Name</dt>
<dd><input type="text" class="form-control"></dd>
<dt>Password</dt>
<dd><input type="password" class="form-control"></dd>
<dt>User Name</dt>
<dd><input type="text" class="form-control"></dd>
<dt>Password</dt>
<dd><input type="password" class="form-control"></dd>
<dt>User Name</dt>
<dd><input type="text" class="form-control"></dd>
<dt>Password</dt>
<dd><input type="password" class="form-control"></dd>
<dt>User Name</dt>
<dd><input type="text" class="form-control"></dd>
<dt>Password</dt>
<dd><input type="password" class="form-control"></dd>
<dt>User Name</dt>
<dd><input type="text" class="form-control"></dd>
<dt>Password</dt>
<dd><input type="password" class="form-control"></dd>
</dl>
</div>
<div class="modal-footer">
<button class="btn btn-primary">Login</button>
<button data-bs-dismiss="modal" class="btn btn-danger">Cancel</button>
</div>
</div>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
3. Badge
- It is used to highlight and content in block.
Class:
.badge
.bg-{contextual}
.text-{contextual}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h2>Table of Contents</h2>
<ul class="list-unstyled">
<li class="bg-dark text-white mb-2 p-2 d-flex justify-content-between"><span>HTML</span>
<span class="badge bg-light text-dark rounded-circle">1</span></li>
<li class="bg-dark text-white mb-2 p-2 d-flex justify-content-between"><span>CSS</span> <span
class="badge bg-light text-dark rounded-circle">4</span></li>
<li class="bg-dark text-white mb-2 p-2 d-flex justify-content-between"><span>Bootstrap</span>
<span class="badge bg-light text-dark rounded-circle">6</span></li>
<li class="bg-dark text-white mb-2 p-2 d-flex justify-content-between"><span>JavaScript</span>
<span class="badge bg-light text-dark rounded-circle">8</span></li>
</ul>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
4. Collapse
- It is used to show or hide any content in page.
Classes:
.collapse
.show
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h2>Frequenty Asked Questions</h2>
<div>
<button data-bs-toggle="collapse" data-bs-target="#q1" class="btn btn-dark w-100">What is
Netflix?</button>
<div class="collapse p-2 bg-dark mt-1 text-white" id="q1">
<p>Netflix is a streaming service that offers a wide variety of award-winning TV shows, movies,
anime, documentaries and more – on thousands of internet-connected devices.</p>
<p>You can watch as much as you want, whenever you want, without a single ad – all for one
low monthly price. There's always something new to discover, and new TV shows and movies are
added every week!</p>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
5. Accordion
- It is combination of multiple items which can collapse using Mutext mechanism.
Classes:
.accordion
.accordion-collapse
.accordion-item
.accordion-header
.accordion-button
.accordion-body
.accordion-footer
Attribute
data-bs-parent : It is used to define mutex
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h2>Frequenty Asked Questions</h2>
<div class="accordion" id="faqs">
<div class="accordion-item">
<div class="accordion-header">
<button class="accordion-button" data-bs-toggle="collapse" data-bs-target="#q1">What is
Netflix?</button>
</div>
<div class="accordion-collapse collapse" id="q1" data-bs-parent="#faqs">
<div class="accordion-body">
<p>Netflix is a streaming service that offers a wide variety of award-winning TV shows,
movies, anime, documentaries and more – on thousands of internet-connected devices.</p>
<p>You can watch as much as you want, whenever you want, without a single ad – all for
one low monthly price. There's always something new to discover, and new TV shows and movies are
added every week!</p>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-header">
<button class="accordion-button" data-bs-toggle="collapse" data-bs-target="#q2">How
much does Netflix cost?</button>
</div>
<div class="accordion-collapse collapse" id="q2" data-bs-parent="#faqs">
<div class="accordion-body">
<p>Netflix is a streaming service that offers a wide variety of award-winning TV shows,
movies, anime, documentaries and more – on thousands of internet-connected devices.</p>
</div>
</div>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
6. Cards
- It is used for designing cards with graphic and various sections.
Classes:
.card
.card-header
.card-body
.card-footer
.card-img-top
.card-img-bottom
.card-img-overlay
.card-title
.card-subtitle
.card-text
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="mt-3 d-flex flex-wrap">
<div class="card p-2 m-2" style="width: 250px;">
<div class="card-footer">
<button class="btn btn-success w-100"> <span class="bi bi-cart"></span> Shop</button>
</div>
</div>
Sudhakar Sharma
1. Alerts
2. Badge
3. Modal
4. Cards
5. Collapse
6. Accordion
Carousel
- It is used to display sliding and fading content in page.
Basic Carousel:
.carousel
.carousel-inner
.carousel-item
- Carousel can have multiple items but one item must be active.
- Carousel can't start animation by default. You have to define the attribute
.slide
.carousel-fade
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="carousel slide mt-1" id="banners" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item">
<img src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item">
<img src="../public/images/[Link]" class="w-100 d-block">
</div>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Carousel Controls:
.carousel-control-prev
.carousel-control-prev-icon
.carousel-control-next
.carousel-control-next-icon
Attributes
.data-bs-slide-next
.data-bs-slide-prev
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="carousel carousel-dark slide mt-1" id="banners" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item">
<img src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item">
<img src="../public/images/[Link]" class="w-100 d-block">
</div>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
.carousel-indicators
data-bs-slide-to="indexNumber"; 0 = first slide
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="carousel carousel-dark slide mt-1" id="banners" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
</div>
<div class="carousel-indicators">
<button class="active" data-bs-slide-to="0" data-bs-target="#banners"></button>
<button data-bs-slide-to="1" data-bs-target="#banners"></button>
<button data-bs-slide-to="2" data-bs-target="#banners"></button>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="carousel carousel-dark slide mt-1" id="banners" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active" data-bs-interval="3000">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item" data-bs-interval="1000">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item" data-bs-interval="5000">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
</div>
<div class="carousel-indicators">
<button class="active" data-bs-slide-to="0" data-bs-target="#banners"></button>
<button data-bs-slide-to="1" data-bs-target="#banners"></button>
<button data-bs-slide-to="2" data-bs-target="#banners"></button>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="carousel carousel-dark slide mt-1" id="banners" data-bs-ride="carousel">
<button class="carousel-control-prev" data-bs-target="#banners" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
</button>
<button class="carousel-control-next" data-bs-target="#banners" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
</button>
<div class="carousel-inner">
<div class="carousel-item active" data-bs-interval="3000">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item" data-bs-interval="1000">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
<div class="carousel-item" data-bs-interval="5000">
<div style="height: 300px;" class="d-flex justify-content-center align-items-center">
<div>
<p>Register for more content</p>
<div class="input-group input-group-lg">
<input type="email" placeholder="Your email address" class="form-control">
<button class="btn btn-danger">Get Started <span class="bi
bi-chevron-right"></span> </button>
</div>
</div>
</div>
</div>
<div class="carousel-item" data-bs-interval="5000">
<img style="height: 300px;" src="../public/images/[Link]" class="w-100 d-block">
</div>
</div>
<div class="carousel-indicators">
<button class="active" data-bs-slide-to="0" data-bs-target="#banners"></button>
<button data-bs-slide-to="1" data-bs-target="#banners"></button>
<button data-bs-slide-to="2" data-bs-target="#banners"></button>
<button data-bs-slide-to="3" data-bs-target="#banners"></button>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Dropdown
.dropdown
.dropup
.dropend
.dropstart
.dropdown-toggle
.dropdown-menu
.dropdown-item
.dropdown-text
.dropdown-link
.dropdown-divider
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h3>Dropdown Demo</h3>
<div class="dropend">
<button data-bs-toggle="dropdown" class="dropdown-toggle btn btn-dark"><span class="bi bi-
globe"></span> Language</button>
<ul class="dropdown-menu dropdown-menu-dark">
<li ><a href="#" class="dropdown-item"><span
class="dropdown-text">English</span></a></li>
<li ><a href="#" class="dropdown-item"><span class="dropdown-
text">हिंदी</span></a></li>
<li class="dropdown-divider"></li>
<li><a href="#" class="dropdown-item">Help?</a></li>
</ul>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="mt-3">
<ul class="nav nav-pills">
<li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#basic"><span class="nav-
text">Basic Details</span></a></li>
<li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#preview"><span
class="nav-text">Preview</span></a></li>
<li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#features"><span
class="nav-text">Features</span></a></li>
</ul>
<div class="tab-content mt-4">
<div class="tab-pane active" id="basic">
<h3>realme C55 (Rainforest, 128 GB)</h3>
<div>
<span class="bg-success p-2 rounded text-white">4.4 <span class="bi
bi-star-fill"></span></span> <span class="ratings-count"><b><font color="gray">12,315 Ratings &
661 Reviews</font></b></span>
</div>
</div>
<div class="tab-pane" id="preview">
<img src="../public/images/[Link]" width="300" height="400">
</div>
<div class="tab-pane" id="features">
<ul type="disc">
<li>8 GB RAM | 128 GB ROM | Expandable Upto 1 TB</li>
<li>17.07 cm (6.72 inch) Full HD+ Display</li>
<li>64MP + 2MP | 8MP Front Camera</li>
<li>5000 mAh Battery</li>
<li>Helio G88 Processor</li>
<li>1 Year Manufacturer Warranty for Phone and 6 Months Warranty for In the Box
Accessories</li>
</ul>
</div>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Bootstrap Components
Sudhakar Sharma
Navbar
- It is used to design responsive navigation bar.
.navbar
.navbar-expand-{lg, sm}
.navbar-toggler
.navbar-toggler-icon
.navbar-brand
.navbar-nav
.nav-item
.nav-link
.navbar-collapse
.navbar-light | dark
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<div class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<button class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#menu">
<span class="navbar-toggler-icon"></span>
</button>
<h3 class="navbar-brand">Shopper.</h3>
<div class="navbar-collapse collapse" id="menu">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link">Home</a></li>
<li class="nav-item"><a class="nav-link">Shop</a></li>
<li class="nav-item"><a class="nav-link">Pages</a></li>
<li class="nav-item"><a class="nav-link">Catalog</a></li>
<li>
<div class="input-group">
<input type="text" class="form-control" placeholder="Search Amazon">
<button class="btn btn-warning"><span class="bi bi-search"></span></button>
</div>
</li>
</ul>
</div>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Buttons
.btn
.btn-{contextual}
.btn-outline-{contextual}
.btn-sm
.btn-lg
.btn-group
.btn-group-lg
.btn-toolbar
.btn-link
.btn-close
Forms
.form-control
.form-range
.form-control-color
.form-control-file
.form-label
.form-check-label
.form-check-input
.form-switch
.form-select
Input Group
.input-group
.input-group-sm|lg
.input-group-text
Pagination
.pagination-{sm|lg}
.page-item
.page-link
.page-text
Tables
.table
.table-hover
.table-bordered
.table-stripped
.table-{contextual}
.table-responsive
.caption-top
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<table class="table table-hover caption-top">
<caption>Products Info</caption>
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Stock</th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3" align="center">
<ul class="pagination">
<li class="page-item"><a class="page-link"><span
class="page-text">«</span></a></li>
<li class="page-item"><a class="page-link"><span class="page-text">1</span></a></li>
<li class="page-item active"><a class="page-link"><span
class="page-text">2</span></a></li>
<li class="page-item"><a class="page-link"><span class="page-text">3</span></a></li>
<li class="page-item"><a class="page-link"><span class="page-text">4</span></a></li>
<li class="page-item"><a class="page-link"><span
class="page-text">»</span></a></li>
</ul>
</td>
</tr>
</tfoot>
</table>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
</head>
<body class="container-fluid">
<h2>Spinners</h2>
<div class="spinner-border text-success"></div>
<div class="spinner-grow text-danger"></div>
<h2>Progress</h2>
<div class="progress">
<div class="progress-bar progress-bar-animated progress-bar-striped bg-success"
style="width:20%">
20% Completed
</div>
<div class="progress-bar progress-bar-animated progress-bar-striped bg-warning" style="width:
60%;">
60% Processing
</div>
<div class="progress-bar progress-bar-animated progress-bar-striped bg-danger" style="width:
20%;">
20% Remaining
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<style>
.register span {
display: inline-block;
}
.left-line, .right-line {
border-top: 1px solid gray;
width: 100px;
}
.register {
display: flex;
align-items: center;
}
.text {
padding-left: 20px;
padding-right: 20px;
}
</style>
</head>
<body class="container-fluid">
<div class="register">
<span class="left-line"></span>
<span class="text">New to Amazon?</span>
<span class="right-line"></span>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
JavaScript
Sudhakar Sharma
JavaScript
- JavaScript is an light weight interpretted and JIT [Just in Time] compiled programming language.
- Interpretted language can translate the code line-by-line.
- Compiled language can translate all lines simultaneously at the same time.
- There are 2 compiling technique
a) JIT [Just in Time]
b) AOT [Ahead of Time]
- JIT translates the code in browser.
- AOT translates at application level.
Note: JavaScript is not an OOP language. It supports only few features of OOP.
Evolution of JavaScript
-------------------------------
- In early day's of Web [1990]
Browser : Mosaic
Markup : GML, SGML, HTML
Script : ECMA Script
- In 1995 Netscape
Browser : Netscape communicator
Markup : HTML
Script : ECMA Script
- Netscape given the responsibility of Live Script to "Sun Micro Systems" [Java]
- Netscape => JavaScript => ECMA => ECMA 2015 [ES5].... ECMA Script 2022 [ES2022]
ES6 to ES2022
Drawbacks of JavaScript:
Sudhakar Sharma
- It is not strictly typed implicitly. It is about the programming standards and rules.
- Extensibility Issues.
Syntax:
<body>
<noscript>
please enable javascript on your browser
</noscript>
</body>
Inline JavaScript
- In this method JavaScript functions are written directly in HTML element.
- You can't reuse the code.
- However it is faster.
Syntax:
<button onclick="[Link]()"> Print </button>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inline</title>
<style media="print">
button {
display: none;
}
</style>
</head>
<body>
<h1>Click Print button to print your Ticket</h1>
<button onclick="[Link]()">Print</button>
</body>
</html>
2. Embedded JavaScript
- In this technique JavaScript functions are defined in a <script> element.
- So that you can re-use the functions from any location in page.
- You can embed in <head> or <body> sections.
- JavaScript MIME type is "text/javascript" or "language=javascript".
Syntax:
<head>
<script type="text/javascript">
..... your functions.......
</script>
</head>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inline</title>
<style media="print">
button {
display: none;
}
</style>
<script type="text/javascript">
function PrintPage(){
[Link]();
}
</script>
</head>
<body>
<h1>Click Print button to print your Ticket</h1>
<button onclick="PrintPage()">Print</button>
</body>
</html>
Syntax:
[Link]
function PrintPage(){
[Link]();
}
<head>
<script type="text/javascript" src="../src/scripts/[Link]"> </script>
</head>
- Using an external file will increase the number of requests to page and also the page load time.
Ex:
1. Add a new folder into project "src"
src\scripts
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inline</title>
<style media="print">
button {
display: none;
}
</style>
<script type="text/javascript" src="../src/scripts/[Link]">
</script>
</head>
<body>
<h1>Click Print button to print your Ticket</h1>
<button onclick="PrintPage()">Print</button>
</body>
</html>
Syntax:
<script type="text/javascript">
"use strict";
.....your functions........
</script>
Syntax:
<!--
function PrintPage(){
[Link]();
}
-->
Sudhakar Sharma
•
Syntax:
[Link][ ]
[Link][ ].elements[ ]
[Link][]
Issue:
- Adding or removing elements in page design will cause change in index number,
which we have update every time.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function bodyload(){
[Link][0].src = "../public/images/[Link]";
[Link][0].elements[2].value = "Login";
[Link][1].elements[1].value = "Register";
}
</script>
</head>
<body onload="bodyload()">
<div>
<img width="100" height="100" border="1">
</div>
<div>
<form>
<h3>User Login</h3>
<input type="text" placeholder="User Name"> <input placeholder="Password"
type="password"> <input type="button">
</form>
</div>
<div>
<form>
<h3>Register User</h3>
Your Email : <input type="email"> <input type="button">
</form>
</div>
</body>
</html>
Syntax:
<img name="pic">
[Link] = "path";
Issues:
- You can't access a child element directly without refering to its parent.
- You have to define the complete hierarchy.
- Name can be common for multiple elements.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function bodyload(){
[Link] = "../public/images/[Link]";
[Link] = "Login";
[Link] = "Register";
}
</script>
</head>
<body onload="bodyload()">
<div>
<img name="pic" width="100" height="100" border="1">
</div>
<div>
<form name="frmLogin">
<h3>User Login</h3>
<input type="text" name="txtUser" placeholder="User Name"> <input name="txtPwd"
placeholder="Password" type="password"> <input name="btnLogin" type="button">
</form>
</div>
<div>
<form name="frmRegister">
<h3>Register User</h3>
Your Email : <input name="txtEmail" type="email"> <input name="btnRegister"
type="button">
</form>
</div>
</body>
</html>
Issues:
- CSS also uses ID as selector.
- In CSS ID can be common for multiple elements
- Every element can't have multiple ID's.
Syntax:
<img id="pic">
[Link]("pic").src = "path";
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function bodyload(){
[Link]("pic").src = "../public/images/[Link]";
[Link]("btnLogin").value = "Login";
[Link]("btnRegister").value = "Register";
}
</script>
</head>
<body onload="bodyload()">
<div>
<img name="pic" id="pic" width="100" height="100" border="1">
</div>
<div>
<form name="frmLogin">
<h3>User Login</h3>
<input type="text" name="txtUser" placeholder="User Name"> <input name="txtPwd"
placeholder="Password" type="password"> <input id="btnLogin" name="btnLogin" type="button">
</form>
</div>
<div>
<form name="frmRegister">
<h3>Register User</h3>
Your Email : <input name="txtEmail" type="email"> <input name="btnRegister"
id="btnRegister" type="button">
</form>
</div>
</body>
</html>
Syntax:
<img>
[Link]("img").src = "path";
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function bodyload(){
[Link]("img").src = "../public/images/[Link]";
[Link]("#btnLogin").value = "Login";
[Link](".btn-register").value = "Register";
}
</script>
</head>
<body onload="bodyload()">
<div>
<img width="100" height="100" border="1">
</div>
<div>
<form name="frmLogin">
<h3>User Login</h3>
<input type="text" name="txtUser" placeholder="User Name"> <input name="txtPwd"
placeholder="Password" type="password"> <input id="btnLogin" name="btnLogin" type="button">
</form>
</div>
<div>
<form name="frmRegister">
<h3>Register User</h3>
Your Email : <input name="txtEmail" type="email"> <input name="btnRegister" class="btn-
register" type="button">
</form>
</div>
</body>
</html>
Issues:
- Class, ID and Type can be common for multiple elements.
Note: JavaScript provides various methods to access all HTML elements with array reference.
[Link]()
[Link]()
[Link]() etc..
Output Techniques:
1. alert()
2. confirm()
3. [Link]()
4. console methods
5. innerHTML
6. innerText
7. outerHTML
alert()
- It pops-up a dialog in window that can display any message.
- It will not allow to cancel the dialog.
- It is RC data type.
- You can define multiple lines using "\n"
Syntax:
alert("line1 \n line2 \n line3");
Sudhakar Sharma
confirm()
- It is similar to alert but allows to cancel.
- It is a boolean method that returns true or false.
true : click OK
false : click Cancel
Syntax:
confirm("message"); => true / false
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Output</title>
<script type="text/javascript">
function DeleteClick(){
flag = confirm("Record will be deleted\nAre you sure?");
if(flag==true){
alert("Record Deleted Successfully..");
} else {
alert("You canceled..");
}
}
</script>
</head>
<body>
<button onclick="DeleteClick()">Delete</button>
</body>
</html>
[Link]()
- It is used to display and render output on new screen.
- It supports complex data to render.
- You render simple text or markup.
Syntax:
[Link]("message | markup");
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Output</title>
<script type="text/javascript">
function DeleteClick(){
flag = confirm("Record will be deleted\nAre you sure?");
if(flag==true){
[Link]("<b><i><font color='red'>Record Deleted
Successfully..</font></i></b><br><a href='[Link]'>Back</a>");
} else {
alert("You canceled..");
}
}
</script>
</head>
<body>
<button onclick="DeleteClick()">Delete</button>
</body>
</html>
innerText
- It is used to display output in containers that can display text.
<div> <span> <dd> <dt> <h2> <p> <blockquote> <td> <li> etc..
- It is RC data type. It will not allow formats for text.
Syntax:
[Link] = "Some message";
innerHTML
- It is similar to innerText but allows formats.
- You can render a message or markup.
Syntax:
[Link] = "message | markup";
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Output</title>
<script type="text/javascript">
function DeleteClick(){
flag = confirm("Record will be deleted\nAre you sure?");
if(flag==true){
[Link]("p").innerHTML = "<font color='red'>Record Deleted
Successfully..</font>";
} else {
[Link]("p").innerText = "Canceled..";
}
}
</script>
</head>
<body>
<button onclick="DeleteClick()">Delete</button>
<p></p>
</body>
</html>
outerHTML
- It is similar to innerHTML but will replace the existing element with target element.
Syntax:
[Link] = "<new element>";
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Output</title>
<script type="text/javascript">
function DeleteClick(){
flag = confirm("Record will be deleted\nAre you sure?");
if(flag==true){
[Link]("p").outerHTML = "<h2><font color='red'>Record Deleted
Successfully..</font></h2>";
} else {
[Link]("p").innerText = "Canceled..";
}
}
</script>
</head>
<body>
<button onclick="DeleteClick()">Delete</button>
<p></p>
</body>
</html>
console methods
- Console is a CLI [Command Line Interface] tool used by developer to test code.
- It is present in every browser "Developer Tools" [right click => inspect]
- The console methods are used to display output in developer tools
[Link]()
[Link]()
[Link]()
[Link]()
[Link]() etc...
- All console methods are RC data type.
- You can use "\n" for line break.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Output</title>
<script type="text/javascript">
function DeleteClick(){
[Link]("User Clicked Delete Button");
flag = confirm("Record will be deleted\nAre you sure?");
if(flag==true){
[Link]("p").innerHTML = "<h2><font color='red'>Record Deleted
Successfully..</font></h2>";
[Link]("Ok clicked and Record Deleted");
} else {
[Link]("p").innerText = "Canceled..";
[Link]("User Canceled");
}
}
</script>
</head>
<body>
<button onclick="DeleteClick()">Delete</button>
<p></p>
</body>
</html>
Summary:
- alert()
- confirm()
- [Link]()
- console methods
- innerHTML
- innerText
- outerHTML
a) Query String
b) Prompt()
c) Form Input Elements
Query String
- A query string is a key and value reference configured in browser URL.
- It allows the user to query any content or to input value from URL. [Address bar]
[Link]
[Link]
prompt()
- It is an input box that pops-up in browser window, from where user can input a value.
- prompt() will return following
null : on cancel
" " [empty string] : on ok without value
string : on ok with value
Syntax:
prompt("Your Message", "default_value_optional");
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function bodyload(){
str = prompt("Your Name","eg:name max 10 chars");
if(str==null){
alert("Input Canceled");
} else if(str==""){
alert("Please provide a name");
} else {
[Link]("p").innerHTML = "Hello ! " + str;
}
}
</script>
</head>
<body onload="bodyload()">
<p></p>
</body>
</html>
Sudhakar Sharma
Input Techniques
- Query String
- Prompt()
Form Elements for Input
- HTML form provides various input elements, from where user can input a value.
[Link]("lblMovie").innerHTML =
[Link]("optMovie").value;
[Link]("lblCinema").innerHTML =
[Link]("optCinema").value;
[Link]("lblDate").innerHTML =
[Link]("optDate").value;
[Link]("lblTime").innerHTML =
[Link]("optTime").value;
[Link]("lblSeats").innerHTML =
[Link]("optSeats").value;
movieName = [Link]("optMovie").value;
imgPoster = [Link]("imgPoster");
if(movieName=="Oppenheimer") {
[Link] = "../public/images/[Link]";
} else {
[Link] = "../public/images/[Link]";
}
}
function ModifyClick(){
[Link]("btnBook").innerHTML="Update";
[Link]("btnBook").className = "btn btn-warning";
}
</script>
</head>
<body class="container-fluid">
<div class="mt-3" id="btnContainer">
<button data-bs-toggle="modal" data-bs-target="#book" class="btn btn-danger">Quick
Booking</button>
</div>
<div class="modal fade" id="book">
<div class="modal-dialog modal-fullscreen">
<div class="modal-content">
<div class="modal-header">
<h4>Quick Booking</h4>
<button class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="p-2 d-flex justify-content-between">
<div>
<select class="form-select" id="optMovie">
<option>Select Movie</option>
<option>Oppenheimer</option>
<option>Barbie</option>
</select>
</div>
<div>
<select class="form-select" id="optCinema">
<option>Select Cinema</option>
<option>B'Hills</option>
<option>Ameerpet</option>
</select>
</div>
<div>
<select class="form-select" id="optDate">
<option>Select Date</option>
<option>TODAY 27 July</option>
<option>TOMORROW 28 July</option>
</select>
</div>
<div>
<select class="form-select" id="optTime">
<option>Select Time</option>
<option>10:30 AM</option>
<option>11:00 PM</option>
</select>
</div>
<div>
<select class="form-select" id="optSeats">
<option>Select Seats</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
<div>
<button id="btnBook" onclick="BookClick()" data-bs-dismiss="modal" class="btn btn-
danger">Book</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="w-25 mt-4" id="summaryContainer" style="display:none">
<h3 class="bg-dark text-white text-center">Booking Summary</h3>
<img width="200" height="200" id="imgPoster" border="1">
<button data-bs-toggle="modal" data-bs-target="#book" class="btn btn-link"
onclick="ModifyClick()">Modify Booking</button>
<dl class="row">
<dt class="col-2">Movie</dt>
<dd class="col-10" id="lblMovie"></dd>
<dt class="col-2">Cinema</dt>
<dd class="col-10" id="lblCinema"></dd>
<dt class="col-2">Date</dt>
<dd class="col-10" id="lblDate"></dd>
<dt class="col-2">Time</dt>
<dd class="col-10" id="lblTime"></dd>
<dt class="col-2">Seats</dt>
<dd class="col-10" id="lblSeats"></dd>
</dl>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Input</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<script type="text/javascript">
function RegisterClick(){
[Link]("btnContainer").[Link] = "none";
[Link]("detailsContainer").[Link] = "block";
[Link]("lblName").innerHTML =
[Link]("txtName").value;
[Link]("lblPrice").innerHTML =
[Link]("txtPrice").value;
[Link]("lblCity").innerHTML =
[Link]("optCity").value;
stockCheckBox = [Link]("chkStock");
stockStatus = "";
if([Link]) {
stockStatus = "Available";
} else {
stockStatus = "Out of Stock";
}
[Link]("lblStock").innerHTML = stockStatus;
}
</script>
</head>
<body class="container-fluid">
<div class="mt-3" id="btnContainer">
<button data-bs-target="#register" data-bs-toggle="modal" class="btn btn-success">Add
Product</button>
</div>
<div class="modal fade" id="register">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h3>Register Product</h3>
<button class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<dl>
<dt>Name</dt>
<dd><input class="form-control" type="text" id="txtName"></dd>
<dt>Price</dt>
<dd><input type="number" id="txtPrice" class="form-control"></dd>
<dt>Stock</dt>
<dd class="form-switch">
<input type="checkbox" id="chkStock" class="form-check-input"> <label class="form-
check-label"> Available </label>
</dd>
<dt>Shipped To</dt>
<dd>
<select id="optCity" class="form-select">
<option>Delhi</option>
<option>Hyderabad</option>
</select>
</dd>
</dl>
</div>
<div class="modal-footer">
<button onclick="RegisterClick()" data-bs-dismiss="modal" class="btn btn-
primary">Register</button>
<button data-bs-dismiss="modal" class="btn btn-danger">Cancel</button>
</div>
</div>
</div>
</div>
<div id="detailsContainer" style="display: none;">
<h3>Product Details</h3>
<table class="table table-hover table-dark w-25">
<tr>
<td>Name</td>
<td id="lblName"></td>
</tr>
<tr>
<td>Price</td>
<td id="lblPrice"></td>
</tr>
<tr>
<td>Stock</td>
<td id="lblStock"></td>
</tr>
<tr>
<td>Shipped To</td>
<td id="lblCity"></td>
</tr>
</table>
<div>
<button data-bs-target="#register" data-bs-toggle="modal" class="btn
btn-link">Modify</button>
</div>
</div>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
JavaScript Variables
Sudhakar Sharma
Variables
- Variables are storage locations in memory, where you can store a value and use it as a part of any
expression.
- You can reuse a value by storing it in variable.
<script>
[Link]("Hello ! " + prompt("Enter Name") + "<br>" + "Hey ! " + prompt("Enter Name") + "
what are you doing today?");
</script>
<script>
userName = prompt("Enter Name");
[Link]("Hello ! " + userName + "<br>" + "Hey ! " + userName + " what are you doing
today?");
</script>
Variable Configuration:
-------------------------------
- Every variable configuration comprises of 3 phases
a) Declaration
b) Assignment
c) Initialization
- Declaration is configuring variable reference name with set of rules.
var userName;
var price;
- Assignment is the process of configuring a value into variable after the declaration.
userName = "John";
price = 3000;
- Initialization is the process of configuring a value into variable at the time of declaration.
<script>
x = 10; // valid
[Link]("X=" + x);
</script>
<script>
"use strict";
x = 10; // invalid
[Link]("X=" + x);
</script>
What is var ?
- It configure a function scope variable.
- You can declare in any block of a function and can access from any another block in the function.
- It allows declaring, assignment and initialization.
Ex:
<script>
"use strict";
function f1()
{
var x; // declaring
x = 10; // assignment
if(x==10)
{
var y = 20; // initialization
}
[Link]("x=" + x + "<br>" + "y=" + y);
}
f1();
</script>
- It allows shadowing.
- Shadowing is the prcoess of declaring or initializing same name identifier within the scope.
{
var y = 10; // initialization
y = 20; // assignment
y = 30; // assignment
var y = 40; // shadowing
}
Ex:
<script>
"use strict";
function f1()
{
var x; // declaring
x = 10; // assignment
if(x==10)
{
var y = 20; // initialization
y = 30; // assignment
var y = 40; // shadowing
}
[Link]("x=" + x + "<br>" + "y=" + y);
}
f1();
</script>
x = 10;
[Link]("X=" + x);
var x; // hoisting
EX:
<script>
"use strict";
function f1()
{
x = 10;
[Link]("x=" + x);
var x; // hoisting
}
f1();
</script>
What is let ?
- It configures a block scope variable.
- It is accessible in the block where it is configured and to its inner blocks.
- It supports declaring, assignment and initialization.
Ex:
<script>
"use strict";
function f1()
{
let x;
x = 10;
if(x==10)
{
let y = 20;
[Link]("x=" + x + "<br>" + "y=" + y);
}
}
f1();
</script>
What is const?
- It configures a block scope variable.
- It will allow only initialization.
- It will not allow declaring and assignment.
<script>
// global
function f1(){
//local
}
// global
</script>
- You can configure a global scope variable by using "var, let or const".
Ex:
<script>
"use strict";
const x=50;
function f1()
{
Sudhakar Sharma
Syntax:
[Link] = value;
Ex:
<script>
"use strict";
function f1()
{
window.x = 30;
[Link]("x in function-1 :" + x + "<br>");
}
function f2()
{
[Link]("x in function-2 :" + x);
}
f1();
f2();
</script>
Variable Naming:
-----------------------
- Name can't start with number.
- Name can be alpha numeric with "_" as special char.
- It can start with alphabet or _ .
- "_" is not recommended in production.
- "_" specifies that it requires further implementation.
var employeeDetails;
var _productName;
FAQ's:
1. What is the result of
var x, y, z = 10;
A:
x = undefined
y = undefined
z = 10
Data Types
---------------
- JavaScript is not a strongly typed language.
- There is no restriction for value type in memory.
- JavaScript is implicitly typed language.
var x = 10; x is number
x = "A"; x is string
x = true; x is boolean
Primitive Types
- They are stored in memory stack. [ LIFO : Last-In-First-Out ]
- They are immutable.
- They have a fixed range for values.
- JavaScript primitive types are
1. number
2. string
3. boolean
4. null
5. undefined
6. symbol
Number Type
- JavaScript number type can handle
Signed Integer - 10
Unsigned Integer 10
Float Point 45.23
Double 345.33, 34.456, 349.34
Decimal 4500.22, 45.3456, 4.78863, [29 decimal places]
Exponent 2e3 [ 2 x 10 (3)] = 2000
Binary 0b1010
Hexa 0xf011
Octa 0o467
Bigint 2n
Syntax:
var x = 2e3;
var x = 0b1010;
var x = 0o1010;
EX:
<script>
var rate = parseFloat(prompt("Enter Interest Rate"));
[Link]("Your interest rate is increase by 1 =" + (rate+1));
</script>
Ex:
<script>
var rate = parseFloat(prompt("Enter Interest Rate"));
if(isNaN(rate)){
[Link]("Please Enter a Number");
} else {
[Link]("Your interest rate is increase by 1 =" + (rate+1));
}
</script>
Number Type
Sudhakar Sharma
Number Type
- Convert string into number
parseInt()
parseFloat()
- Validating Number
isNaN()
- JavaScript provides "Math" object, which comprises of various methods that are used for
manipulating number.
[Link]
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]() etc...
- To build any mathematical expression you need JavaScript arithematic operators
+ Addition
- Substraction
* Multiplication
/ Division
** Exponent
% Modulus
++ Increment
-- Decrement
2**3 8
Post Decrement
var x = 10;
var y = x--; => x=9, y=10
Pre Decrement
var x = 10;
var y = --x; => x = 9, y=9
- You can use Math object functions for handling pre-defined expressions
[Link](2,3) => 8
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EMI Calculator</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<script type="text/javascript">
function AmountChange(){
[Link]("txtAmount").value =
[Link]("amountRange").value;
}
function YearChange(){
[Link]("txtYears").value = [Link]("yearRange").value;
}
function RateChange(){
[Link]("txtRate").value = [Link]("rateRange").value;
}
function CalculateClick(){
var P = parseInt([Link]("txtAmount").value);
var R = parseFloat([Link]("txtRate").value)/12/100;
var N = parseInt([Link]("txtYears").value)*12;
var EMI = P * R * [Link](1+R,N)/[Link](1+R,(N-1));
[Link]("msg").innerHTML = "Your Monthly Installment is <b>₹" +
[Link](EMI) + " </b>for your loan amount ₹ " + P;
}
</script>
</head>
<body class="container-fluid">
<div class="border border-2 p-3 mt-3">
<h3>Personal Loan EMI Calculator</h3>
<div class="row mt-4 mb-3">
<div class="col">
Amount you need ₹ <input type="text" id="txtAmount">
</div>
<div class="col">
for <input type="text" size="4" id="txtYears"> years
</div>
<div class="col">
Interest rate <input type="text" size="4" id="txtRate"> %
</div>
</div>
<div class="row mt-4 mb-3">
<div class="col">
<input type="range" onchange="AmountChange()" class="form-range" id="amountRange"
min="10000" max="500000" value="10000">
<div class="d-flex justify-content-between">
<span>₹ 10,000</span>
<span>₹ 5,00,00</span>
</div>
</div>
<div class="col">
<input type="range" onchange="YearChange()" min="1" class="form-range" id="yearRange"
max="5" value="1">
<div class="d-flex justify-content-between">
<span>1</span>
<span>5</span>
</div>
</div>
<div class="col">
<input type="range" onchange="RateChange()" min="10.43" class="form-range"
id="rateRange" step="0.01" max="18.43" value="10.43">
<div class="d-flex justify-content-between">
<span>10.43%</span>
<span>18.43%</span>
</div>
</div>
</div>
<div class="mt-4 row mb-4">
<div class="col text-end">
<button onclick="CalculateClick()" class="btn btn-primary">Calculate</button>
</div>
</div>
</div>
<p id="msg" class="mt-4 text-center"></p>
</body>
</html>
String Type
String Type
Sudhakar Sharma
Aug 1, 2023
String Types
- String is a literal with group of characters enclosed in
a) dobule quotes " "
b) single quotes ' '
c) back ticks ` `
- Single and double quotes are used to configure outer and inner strings.
Syntax:
var link = "<a href='[Link]'> Home </a>";
var link = '<a href="[Link]"> Home </a>';
- Single and double quote requires lot of concatenation with dynamic values.
Ex:
<script>
var userName = prompt("Enter Name");
var age = parseInt(prompt("Enter Age"));
var msg1 = "Hello !" + " " + userName + " " + "you will be" + " " + (age+1) + " " + "next year";
[Link](msg1);
</script>
- JavaScript ES5+ version introduced backtick, which configure a string with embedded expression.
- You can use a data binding expression "${ }" with backticks.
- Data binding expression is not allowed with single and double quotes.
Syntax:
`your string ${ expression } your string`;
Ex:
<script>
var userName = prompt("Enter Name");
var age = parseInt(prompt("Enter Age"));
var msg1 = "Hello !" + " " + userName + " " + "you will be" + " " + (age+1) + " " + "next year<br>";
var msg2 = `Hello ! ${userName} you will be ${(age+1)} next year.`;
[Link](msg1);
[Link](msg2);
</script>
- Several string characters are non-printable, to print the non-printable chars you need escape
sequence character " \ ".
Ex:
<script>
var path = "\"D:\\project\\images\\[Link]\"";
[Link](path);
</script>
- JavaScript provides various methods for formatting a string dynamically, format includes font, style
and effects.
Note: String formatting methods are not suitable for RC data type elements.
[Link]("p").innerHTML = "Hello".bold().italics();
<b><i>Hello</i></b>
[Link]("textBox").value = "Hello".bold()
Ex:
<script>
var msg = "Welcome to JavaScript";
[Link]([Link]('red').fontsize(6).bold().italics());
</script>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function ChangeCase(){
var userName = [Link]("txtName").value;
[Link]("txtName").value = [Link]();
}
</script>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd>
<input type="text" onblur="ChangeCase()" id="txtName" placeholder="Name in Block
Letters">
</dd>
</dl>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function BoldClick(){
[Link]("msg").innerHTML = "Welcome to JavaScript".bold();
}
function ItalicClick(){
[Link]("msg").innerHTML = "Welcome to JavaScript".italics();
}
</script>
</head>
<body>
<div>
<button onclick="BoldClick()">B</button>
<button onclick="ItalicClick()">I</button>
<button>Strike</button>
</div>
<p id="msg">Welcome to JavaScript</p>
</body>
</html>
Syntax:
var str = "Welcome";
[Link]; => 7
[Link](0); => W
[Link](0); => 86 [A = 65, Z = 90]
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function VerifyName(){
var userName = [Link]("txtName").value;
var nameError = [Link]("nameError");
if([Link]==0){
[Link] = "User Name Required".fontcolor('red');
} else {
if([Link](0)=="A"){
[Link] = "";
} else {
[Link] = "Name must start with 'A' ".fontcolor('gold');
}
}
}
</script>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" onblur="VerifyName()" id="txtName"></dd>
<dd id="nameError"></dd>
</dl>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function VerifyName(){
var userName = [Link]("txtName").value;
var nameError = [Link]("nameError");
if([Link]==0){
[Link] = "User Name Required".fontcolor('red');
} else {
if([Link](0)>=65 && [Link](0)<=90){
[Link] = "";
} else {
[Link] = "Name must start with uppercase letter".fontcolor('red');
}
}
}
</script>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" onblur="VerifyName()" id="txtName"></dd>
<dd id="nameError"></dd>
</dl>
</body>
</html>
Sudhakar Sharma
Aug 2, 2023
Syntax:
var str = "Welcome";
[Link]("e"); // 1
[Link]("a"); // -1
[Link]("e"); // 6
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String</title>
<script type="text/javascript">
function VerifyEmail(){
var email = [Link]("txtEmail").value;
var emailError = [Link]("emailError");
var atPos = [Link]("@");
var dotPos = [Link](".");
if( (atPos<2) || (dotPos-atPos)<4) {
[Link] = "Invalid Email".fontcolor('red');
} else {
[Link] = "";
}
}
</script>
</head>
<body>
<dl>
<dt>Your Email</dt>
<dd><input type="text" id="txtEmail" onblur="VerifyEmail()"></dd>
<dd id="emailError"></dd>
</dl>
</body>
</html>
Syntax:
var str = "Welcome";
[Link]("w"); // false
[Link]("e"); // true
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function VerifyCard(){
var card = [Link]("txtCard").value;
var imgCard = [Link]("imgCard");
if([Link]("4455")) {
[Link] = "../public/images/[Link]";
} else {
[Link] = "../public/images/[Link]";
}
}
function VerifySkype(){
var skype = [Link]("txtSkype").value;
var skypeError = [Link]("skypeError");
if([Link]("[Link]")){
[Link] = "";
} else {
[Link] = "Invalid Skype ID".fontcolor('red');
}
}
</script>
</head>
<body>
<dl>
<dt>Your Card Number</dt>
<dd>
<input onblur="VerifyCard()" type="text" id="txtCard"> <img id="imgCard" width="50"
height="18">
</dd>
<dt>Your Skype Id</dt>
<dd>
<input onblur="VerifySkype()" type="text" id="txtSkype"> <span id="skypeError"></span>
</dd>
</dl>
</body>
</html>
substr : It uses start index and count of chars to read from given index.
Ex:
var viewUrl = "[Link]
var videoCode= ?
<script>
var viewUrl = "[Link]
var videoCode = [Link]([Link]("=")+1);
[Link](`
URL : ${viewUrl} <br>
Code: ${videoCode}
`);
</script>
Ex:
var email = "john_nit2023@[Link]";
var Id = ?
var domain = ?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function GetDetails(){
var email = [Link]("txtEmail").value;
var atPos = [Link]("@");
var id = [Link](0,atPos);
var domain = [Link](atPos+1);
[Link](`
Your Email : ${email} <br>
Your Id : ${id} <br>
Registered At : ${domain}
`);
}
</script>
</head>
<body>
<fieldset>
<legend>Your Email</legend>
<input type="text" id="txtEmail" onblur="GetDetails()">
</fieldset>
</body>
</html>
Syntax:
var str = "john,98822294958,john@[Link]";
var [name,mobile,email] = [Link](',');
<script>
var str = "john,98822294958,john@[Link]";
var [name,mobile,email] = [Link](',');
[Link](`
Name : ${name} <br>
Mobile: ${mobile} <br>
Email : ${email}
`);
</script>
ex: split
Syntax:
var str = " welcome ";
[Link]([Link]());
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function VerifyId(){
var userid = [Link]("txtId").value;
var error = [Link]("error");
if([Link]()=="john_nit"){
[Link] = "";
} else {
[Link] = "Invalid UserId".fontcolor('red');
}
}
</script>
</head>
<body>
<fieldset>
<legend>User Id</legend>
<input type="text" onblur="VerifyId()" id="txtId">
<div id="error"></div>
</fieldset>
</body>
</html>
Sudhakar Sharma
Aug 3, 2023
slice()
substr()
substring()
trim()
split()
match()
- It is used to verify a value by matching it with regular expression.
- It returns a boolean true if value matches the given expression.
Syntax:
[Link](/regularExpression/);
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function ChangeMeter(min, max, value){
var meter = [Link]("meter");
[Link]=min;
[Link] = max;
[Link] = value;
}
function VerifyPassword(){
var password = [Link]("txtPwd").value;
var regExp = /(?=.*[A-Z])\w{4,15}/;
var msg = [Link]("msg");
if([Link](regExp)){
[Link] = "Strong Password".fontcolor('green');
ChangeMeter(1,100,100);
} else {
if([Link]<4){
[Link] = "Poor Password - Min 4 chars required".fontcolor('red');
ChangeMeter(1,100,20);
} else {
[Link] = "Weak Password - Atleast one uppercase letter
required".fontcolor('gold');
ChangeMeter(1,100,60);
}
}
}
</script>
<style>
input, meter {
width: 200px;
}
meter {
height:20px;
}
</style>
</head>
<body>
<fieldset>
<legend>Verify Password</legend>
<input type="password" onkeyup="VerifyPassword()" id="txtPwd">
<div>
<meter min="1" max="100" value="1"></meter>
</div>
<div id="msg"></div>
</fieldset>
</body>
</html>
Summary
- length
- charAt()
- charCodeAt()
- indexOf()
- lastIndexOf()
- startsWith()
- endsWith()
- slice()
- substr()
- substring()
- split()
- trim()
- match()
Boolean Type
- A boolean returns true or false.
- Booleans are used in decision making.
- Boolean contains the keywords "true and false".
- JavaScript boolean value can be compared with 0 and 1.
0 = false
1 = true
Syntax:
var stock = true;
if(stock==1) => not recommended => if(stock==true)
{
statement on true;
}
else
{
statement on false;
}
Syntax:
var stock = 1;
if(stock==true) { => invalid
}
else{
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function SetStock(){
var stockCheckbox = [Link]("stock");
var label = [Link]("lblStock");
if([Link]==true){
[Link] = "Available";
} else {
[Link] = "Out of Stock";
}
}
function ToggleClick(){
var stockCheckbox = [Link]("stock");
[Link] = ([Link]==true)?false:true;
var label = [Link]("lblStock");
[Link] = ([Link]==true)?"Available":"Out of Stock";
}
</script>
</head>
<body>
<div>
<button onclick="ToggleClick()">Toggle</button>
</div>
<input type="checkbox" onchange="SetStock()" id="stock"> <label id="lblStock">Out of
Stock</label>
</body>
</html>
if(condition)
{
statement on true;
}
else
{
statement on false;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<script>
function SortToggle(){
var button = [Link]("button");
[Link] = ([Link]=="bi bi-sort-alpha-down")?"bi bi-sort-alpha-up":"bi bi-
sort-alpha-down";
}
</script>
</head>
<body>
<button onclick="SortToggle()" class="bi bi-sort-alpha-down"></button>
</body>
</html>
Syntax:
<img src="[Link]" id="pic">
<button> Show </button>
function buttonClick(){
var pic = [Link]("pic");
[Link] = ([Link]=="none")?"block":"none";
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<script>
function Toggle(){
var button = [Link]("button");
var pic = [Link]("pic");
[Link] = ([Link]=="bi bi-eye-fill")?"bi bi-eye-slash":"bi bi-eye-fill";
[Link] = ([Link]=="none")?"block":"none";
[Link] = ([Link]=="Hide")?"Show":"Hide";
}
</script>
</head>
<body>
<button onclick="Toggle()" class="bi bi-eye-fill"> Show </button>
<div>
<img src="../public/images/[Link]" style="display:none" width="200" height="200"
id="pic">
</div>
</body>
</html>
Sudhakar Sharma
•
Aug 4, 2023
BigInt
- It is a new data type for large integer values.
- Large intergers have memory issues.
- E5+ version introduced a new way of configuring large integers called BigInt.
- You can configure Large Integers by using "n" as suffix or by using
"[Link]-SAFE-INTEGER()
<script>
var price = 9993838281n;
[Link](`Price=${price}`);
</script>
Symbol
- It configures a hidden key for object.
- Key is ignored over iterations and other collection operations. But it is available to handle
individually.
Syntax:
var Id = Symbol();
var product = {
[Id] : 1,
Name: "TV",
Price : 30400.22
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form>
<h2>Edit Your Details</h2>
<dl>
<dd><input type="hidden" name="UserId" value="john_nit"></dd>
<dt>User Name</dt>
<dd><input type="text" value="John" name="UserName"></dd>
<dt>Age</dt>
<dd><input type="number" value="22" name="Age"></dd>
</dl>
<button>Save</button>
</form>
</body>
</html>
Undefined
- It configures that a variable reference is defined but value is not defined.
- Undefined is the type configured for variable at compile time.
Syntax:
var x;
[Link]("x=" + x); x = undefined
EX:1
<script>
var Name = "Samsung TV";
var Price;
if(Price){
[Link](`Name=${Name}<br>Price=${Price}`);
} else {
[Link](`Name=${Name}`);
}
</script>
Ex2:
<script>
var Name = "Samsung TV";
var Price;
if(Price==undefined){
[Link](`Name=${Name}`);
} else {
[Link](`Name=${Name}<br>Price=${Price}`);
}
</script>
Null
- Null is a value returned when value is not supplied into variable during runtime of application.
- You can verify Null by usig "null" keyword.
Ex:
<script>
var Name = "Samsung TV";
var Price = prompt("Enter Price");
if(Price==null){
[Link](`Name=${Name}`);
}
else if (Price=="") {
[Link](`Name=${Name}`);
}
else {
[Link](`Name=${Name}<br>Price=${Price}`);
}
</script>
Summary
- Number
- String
- Boolean
- Null
- Undefined
- BigInt
- Symbol
Array
- Arrays are introduced into computer programming to reduce overhead and complexity.
- Arrays will reduce overhead by storing values in sequential order.
- Arrays reduce complexity by storing multiple values under one reference name.
- JavaScript array can handle various types of values.
[Few technologies restrict array to similar type: c, c++, java, c#]
Array Configuration
Sudhakar Sharma
Aug 5, 2023
Configuring Array:
- It comprises of 2 phases
a) Declaring Array
b) Intializing or Assigning memory for Array
- Declaring Array is same as other variable types, you can use var, let & const.
var products;
let categories;
const users;
- You can assign value into array memory by the reference of property.
- Property is a string type that maps the Index number.
var values = [ ];
values[0] = 10; => 0 & 1 are properties [string type]
values["1"] = "A";
Ex:
<script>
var values = [10, "A", true];
values[0] = 20;
values["1"] = "B";
for(var property in values){
[Link](`${property}[${typeof property}] : ${values[property]}-${typeof
values[property]}<br>`);
}
</script>
Ex:
<script>
var values = [1, "TV", true, ["Delhi", "Hyd"], prompt("Enter Price"), function()
{[Link]("Hello from Array")}];
[Link](`
Id : ${values[0]} <br>
Name: ${values["1"]} <br>
Stock: ${values[2]} <br>
Cities : ${values[3][0]}, ${values[3][1]} <br>
Price : ${parseFloat(values[4])} <br>
Rating : ${values[6]} <br>
`);
values[5]();
</script>
Ex:
<script>
var values = [1, [["Electronics","Fashion"], ["Delhi", "Hyd"]]];
[Link](values[1][1][1]);
</script>
Ex:
<script>
var values = [1, [["Electronics","Fashion"], ["Delhi", "Hyd"]]];
values[1][1][1] = "Hyderabad";
values[1][1][2] = "Chennai";
[Link](values[1][1][1] + "<br>" + values[1][1][2]);
</script>
Ex:
<script>
var values = [1, [["Electronics","Fashion"], ["Delhi", "Hyd"], [true, function(){[Link]("Hello
Array")}]]];
values[1][1][1] = "Hyderabad";
values[1][1][2] = "Chennai";
[Link](values[1][1][1] + "<br>" + values[1][1][2] + "<br>");
values[1][2][1]();
</script>
Syntax:
var values = [10, 20];
var [a, b] = values; => a = 10, b = 20
Ex:
<script>
var values = [1, "TV", 34000.44, true, ["Delhi", "Hyd"], function(){[Link]("Hello World")}];
var [id, name, price, stock, citites, hello] = values;
[Link](`
Id=${id} <br>
Name=${name} <br>
Stock=${stock} <br>
Cities=${citites} <br>
Price=${price} <br>
`);
hello();
</script>
Array Methods
Sudhakar Sharma
Aug 7, 2023
Array Manipulations
Ex-1:
<script>
var categories = ["All", "Electronics", "Footwear", "Fashion"];
[Link](`
To String : ${[Link]()} <br>
Join : ${[Link]("-->")}
`);
</script>
Ex-2:
<script>
var categories = ["All", "Electronics", "Footwear", "Fashion"];
[Link](function(value){
[Link](`<h2>${value}</h2>`);
})
</script>
Ex-3:
<script>
var categories = ["All", "Electronics", "Footwear", "Fashion"];
[Link](function(value, index){
[Link](`[${index}]:${value}<br>`);
})
</script>
Ex-4:
<script>
var categories = ["All", "Electronics", "Footwear", "Fashion"];
[Link](1,3).map(function(value){
[Link](`<li>${value}</li>`);
})
</script>
Ex-5:
<script>
var sales = [50000, 32000, 68000, 24500, 72000];
var result = [Link](function(value){
return value >= 60000;
});
[Link](result);
</script>
Ex-6:
<script>
var sales = [50000, 32000, 68000, 24500, 72000];
[Link](function(value){
return value >= 60000;
}).map(function(value){
[Link](value + "<br>");
})
</script>
[Link]("nodeName")
2. Configure properties for element
id, name, className, src, href
appendChild()
[Link]("div").appendChild(pic);
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function bodyload(){
var home = [Link]("button");
[Link] = "Home";
[Link]("nav").appendChild(home);
[Link]("figure").appendChild(pic);
[Link]("figure").appendChild(caption);
}
</script>
</head>
<body onload="bodyload()">
<h3>Shopper</h3>
<nav></nav>
<figure>
</figure>
</body>
</html>
Task:
function bodyload(){
var input = [Link]("input");
[Link] = "button";
[Link] = "Register";
[Link]("container").appendChild(input);
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function bodyload(){
var input = [Link]("input");
[Link] = "button";
[Link] = "Register";
[Link]("nav").appendChild(input);
}
</script>
</head>
<body onload="bodyload()">
<h3>Shopper</h3>
<nav></nav>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function bodyload(){
var tr = [Link]("tr");
var td = [Link]("td");
[Link] = "Samsung TV";
[Link](td);
[Link]("tbody").appendChild(tr);
}
</script>
</head>
<body onload="bodyload()">
<table border="1" width="200">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<!--create a row with cell that contains text Samsung TV -->
</tbody>
</table>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function bodyload(){
var ol = [Link]("ol");
var item1 = [Link]("li");
var item2 = [Link]("li");
var item3 = [Link]("li");
[Link] = "HTML";
[Link] = "CSS";
[Link] = "JavaScript";
[Link](item1);
[Link](item2);
[Link](item3);
[Link]("div").appendChild(ol);
}
</script>
</head>
<body onload="bodyload()">
<div>
</div>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var topics = ["HTML", "CSS", "Bootstrap", "JavaScript", "NodeJS"];
function bodyload(){
var ol = [Link]("ol");
[Link](function(value){
var li = [Link]("li");
[Link] = value;
[Link](li);
})
[Link]("div").appendChild(ol);
}
</script>
</head>
<body onload="bodyload()">
<div>
</div>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var topics = ["Choose a Course","HTML", "CSS", "Bootstrap", "JavaScript", "NodeJS"];
function bodyload(){
var select = [Link]("select");
[Link](function(value){
var option = [Link]("option");
[Link] = value;
[Link] = value;
[Link](option);
})
[Link]("div").appendChild(select);
}
</script>
</head>
<body onload="bodyload()">
<div>
</div>
</body>
</html>
Task:
1. Create a Table with rows for every course.
2. Create a Hyperlink for course and link must be added into ordered list.
3. Create a list of checkboxes for every course.
Sudhakar Sharma
Aug 8, 2023
- To read elements from array you can also use loops and external iteration statements.
- Loops are created by using for, while, do while statements.
Syntax:
for(intialization; condition; counter)
{
Ex:
var categories = ["All", "Electronics", "Footwear"];
Ex:
for(var property in categories)
{
[Link](property + "<br>");
}
0
1
2
All
Electronics
Footwear
[0] : All
[1] : Electronics
[2] : Footwear
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var categories = ["All", "Electronics", "Footwear"];
function bodyload(){
[Link](function(category){
var li = [Link]("li");
var input = [Link]("input");
[Link] = "checkbox";
var label = [Link]("label");
[Link] = category;
[Link](input);
[Link](label);
[Link]("ul").appendChild(li);
})
}
</script>
<style>
ul {
list-style: none;
}
</style>
</head>
<body onload="bodyload()">
<ul>
</ul>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var categories = ["All", "Electronics", "Footwear"];
function bodyload(){
[Link](function(category){
var li = [Link]("li");
[Link] = `<input type="checkbox"><label>${category}</label>`;
[Link]("ul").appendChild(li);
})
}
</script>
<style>
ul {
list-style: none;
}
</style>
</head>
<body onload="bodyload()">
<ul>
</ul>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var categories = ["All", "Electronics", "Footwear"];
function bodyload(){
[Link](function(category){
var li = [Link]("li");
[Link] = `<input type="checkbox"><label>${category}</label>`;
[Link]("ul").appendChild(li);
[Link]("ol").appendChild(olLi);
})
}
</script>
<style>
ul,ol {
list-style: none;
}
</style>
</head>
<body onload="bodyload()">
<ul>
</ul>
<ol>
</ol>
</body>
</html>
push() It adds new element(s) as last element i.e towards end of list.
unshift() It adds new element(s) as first element.
splice() It adds new element(s) at specific position.
Syntax:
[Link]("item1", "item2", ...);
[Link]("item1", "item2",...);
[Link](indexNumber, deleteCount, "new Items...");
[Link](2,0, "item1", "item2", ...);
Ex:
[Link](1,0,"Kids Fashion","Women Fashion");
Syntax:
[Link]()
[Link]()
[Link](index, deleteCount)
FAQ: How to remove all items from array? How to empty array?
Ans :
collection = [ ];
[Link] = 0;
Syntax:
[Link]()
[Link]()
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Array Manipulation</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<script type="text/javascript">
var cities = ["Delhi", "Hyd", "Mumbai"];
function LoadCities(){
[Link]("lstCities").innerHTML = "";
[Link](function(city){
var option = [Link]("option");
[Link] = city;
[Link] = city;
[Link]("lstCities").appendChild(option);
})
[Link]("lblCount").innerHTML = `Total No of Cities: ${[Link]}`;
}
function bodyload(){
LoadCities();
}
function AddClick(){
var cityName = [Link]("txtCity").value;
if([Link](cityName)==-1){
[Link](cityName);
LoadCities();
alert(`${cityName} Added to List`);
[Link]("txtCity").value = "";
} else {
alert(`${cityName} Exits in List`);
}
}
function SortAsc(){
[Link]();
LoadCities();
}
function SortDsc(){
[Link]();
[Link]();
LoadCities();
}
function RemoveClick(){
var selectedCity = [Link]("lstCities").value;
var cityIndex = [Link](selectedCity);
var flag = confirm(`Are you sure\nWant to Delete ${selectedCity}`);
if(flag==true){
[Link](cityIndex,1);
LoadCities();
}
}
function ClearClick(){
var flag = confirm("Are you sure\nWant to Delete all?");
if(flag==true){
[Link] = 0;
LoadCities();
}
}
</script>
</head>
<body class="container-fluid" onload="bodyload()">
<div class="mt-4 p-2 w-25">
<div class="input-group">
<input type="text" id="txtCity" placeholder="Add new city" class="form-control"> <button
class="btn btn-primary" onclick="AddClick()">Add</button>
</div>
<div class="mt-3 p-2">
<button onclick="SortAsc()" class="btn btn-primary bi bi-sort-alpha-down"></button>
<button onclick="SortDsc()" class="btn btn-primary bi bi-sort-alpha-up"></button>
<select id="lstCities" class="form-select mt-2" size="3">
</select>
<label class="form-label fw-bold" id="lblCount"></label>
</div>
<div class="mt-3 p-2">
<button class="btn btn-danger" onclick="RemoveClick()"> <span class="bi
bi-trash-fill"></span> Remove</button>
<button class="btn btn-danger" onclick="ClearClick()"> <span class="bi bi-trash"></span>
Clear All</button>
</div>
</div>
</body>
</html>
Sudhakar Sharma
Aug 9, 2023
Object Type
- The concept of object is introduced into computer programming in early 1960's by
"Alan Kay".
- It is used to keep all related data and logic together.
- Object uses Key and Value collection.
- You can store values under the reference of keys.
- Key is string type and value can be any type.
Syntax:
var product = {
"Key" : value,
"Key" : value,
"Key" : function() { }
}
- If object comprises of only data, not any logic then it is reffered as "JSON".
- JSON is JavaScript Object Notation, It is a format for data.
Syntax:
var product = {
"Name": "TV",
"Price": 45000.44,
"Stock": true,
"Cities": ["Delhi", "Hyd"],
"Rating": { "Rate": 4.2, "Count": 4500 }
}
[Link] => TV
- ES6 technique
Ex:
<script>
var tv = {
"Name": "Samsung TV",
"Price": 45000.44,
"Stock": true,
"Cities": ["Delhi", "Hyd"],
"Rating": {"Rate":4.2, "Count": 3400}
}
[Link] = 57000.44;
[Link](`
Name=${[Link]} <br>
Price=${[Link]} <br>
Stock=${[Link]} <br>
Cities=${[Link]("/")} <br>
Rating= ${[Link]} [${[Link]}]
`);
</script>
}
}
- You can access the members of object within object by using "this" keyword.
Ex:
<script>
var tv = {
"Name": "Samsung TV",
"Price": 45000.44,
"Qty": 0,
"Stock": true,
"Cities": ["Delhi", "Hyd"],
"Rating": {"Rate":4.2, "Count": 3400},
"Total": function(){
return [Link] * [Link];
},
"Print": function(){
[Link](`
Name=${[Link]} <br>
Price=${[Link]} <br>
Stock=${[Link]} <br>
Cities=${[Link]("/")} <br>
Rating= ${[Link]} [${[Link]}] <br>
Qty=${[Link]} <br>
Total=${[Link]()}
`);
}
}
[Link] = parseInt(prompt("Enter Quantity"));
[Link]();
</script>
fetch() Initial
.then() resolved
.catch() rejected
Syntax:
fetch("path").then(function(response){}).catch(function(error){})
Ex:
1. Add a new folder into project
"data"
{
"Title": "realme C53 (Champion Gold, 64 GB)",
"Price": 10999,
"Rating": {"Rate":4.6, "Count":9952, "Reviews":420},
"Features":["6 GB RAM | 64 GB ROM | Expandable Upto 2 TB", "17.12 cm (6.74 inch) HD Display",
"108MP + 2MP | 8MP Front Camera","5000 mAh Battery","T612 Processor"],
"Photo": "../public/images/[Link]"
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<script type="text/javascript">
function bodyload(){
fetch("../data/[Link]")
.then(function(response){
return [Link]();
})
.then(function(product){
[Link]("prodImg").src= [Link];
[Link]("title").innerHTML = [Link];
[Link]("rating").innerHTML = `<span class="bg-success text-white p-2
rounded">${[Link]} <span class="bi bi-star-fill"></span> </span> <span class="fw-bold
ps-3">${[Link]} Ratings & ${[Link]} Reviews</span>`;
[Link](function(feature){
var li = [Link]("li");
[Link] = feature;
[Link]("ul").appendChild(li);
});
[Link]("price").innerHTML = `₹ ${[Link]}`;
})
}
</script>
</head>
<body class="container-fluid" onload="bodyload()">
<div class="row mt-4">
<div class="col-2">
<img id="prodImg" width="250">
</div>
<div class="col-8 ps-4">
<h2 id="title"></h2>
<div id="rating"></div>
<ul id="features" class="mt-4">
</ul>
</div>
<div class="col-2">
<h2 id="price"></h2>
</div>
</div>
</body>
</html>
Sudhakar Sharma
Object Manipulations
-----------------------------
1. How to delete any Key from object?
A. By using delete operator.
product = {
Name: "TV",
Price: 45000.33
}
delete [Link];
Ex:
<script>
var product = {
Name: "TV",
Price: 45000.33
}
if("Price" in product){
[Link](`Name=${[Link]}<br>Price=${[Link]}`);
} else {
[Link](`Name=${[Link]}`);
}
</script>
Syntax:
for(var key in objectName)
{
[Link](key + "<br>");
}
Ex:
<script>
fetch("../data/[Link]")
.then(function(response){
return [Link]();
})
.then(function(product){
for(var property in product){
[Link](`${property}<br>`);
}
})
</script>
Syntax:
[Link](objectName).map(function(key){
[Link](key);
})
Ex:
<script>
fetch("../data/[Link]")
.then(function(response){
return [Link]();
})
.then(function(product){
[Link](product).map(function(key){
[Link](`${key}<br>`);
})
})
</script>
Ex:
<script>
fetch("../data/[Link]")
.then(function(response){
return [Link]();
})
.then(function(product){
[Link](product).map(function(key){
[Link](`${key}:${typeof product[key]}<br>`);
})
})
</script>
Ex:
<script>
fetch("../data/[Link]")
.then(function(response){
return [Link]();
})
.then(function(product){
[Link](product).map(function(key){
[Link](`${key}:${typeof product[key]}<br>`);
})
[Link](`Total Number of Keys : ${[Link](product).length} `);
})
</script>
Array of Objects
- Array can configure multiple objects.
- Usually data is returned from API as Object or Array.
- Complex data is configured in the form of "Array of Objects".
Syntax:
[
{ [0] => Object
},
{ [1] => Object
}
]
Ex:
1. Add a new file into data folder
"[Link]"
[
{
"Name": "Samsung TV",
"Price": 45000.44,
"Stock": true
},
{
"Name":"Nike Casuals",
"Price": 2000.44,
"Stock": false
},
{
"Name":"Watch",
"Price": 5000.33,
"Stock":true
}
]
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link](tdName);
[Link](tdPrice);
[Link](tdStock);
[Link]("tbody").appendChild(tr);
})
})
}
</script>
</head>
<body>
<div>
<button onclick="FetchClick()">Fetch Products</button>
</div>
<br><br>
<table width="100%" border="1">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Stock</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
Nasa API
[Link] => provides NASA data for Application Developers => JSON Format
Ex: Table
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<script>
function FetchClick(){
fetch("[Link]
sol=1000&api_key=DEMO_KEY")
.then(function(res){
return [Link]();
})
.then(function(marsObject){
[Link](function(item){
var tr = [Link]("tr");
var tdId = [Link]("td");
var tdImage = [Link]("td");
var tdCamera = [Link]("td");
var tdRover = [Link]("td");
[Link] = [Link];
[Link] = `<a href=${item.img_src} target="_blank"><img width="200"
height="200" src=${item.img_src}></a>`;
[Link] = [Link].full_name;
[Link] = [Link];
[Link](tdId);
[Link](tdImage);
[Link](tdCamera);
[Link](tdRover);
[Link]("tbody").appendChild(tr);
})
})
}
</script>
</head>
<body class="container-fluid">
<button onclick="FetchClick()" class="btn btn-primary mt-3 mb-3">Fetch Data</button>
<table class="table table-hover">
<thead>
<tr>
<th>Photo Id</th>
<th>Preview</th>
<th>Camera Name</th>
<th>Rover Name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<script>
function FetchClick(){
alert("Data Fetched..");
fetch("[Link]
sol=1000&api_key=DEMO_KEY")
.then(function(res){
return [Link]();
})
.then(function(marsObject){
[Link](function(item){
var card = [Link]("div");
[Link] = "card m-2 p-2";
[Link] = "200px";
[Link] = `
<a href=${item.img_src} target="_blank"><img src=${item.img_src} class="card-img-
top" height="200"></a>
<div class="card-body">
<dl>
<dt>Photo Id</dt>
<dd>${[Link]}</dd>
<dt>Camera</dt>
<dd>${[Link].full_name}</dd>
<dt>Rover</dt>
<dd>${[Link]}</dd>
</dl>
</div>
`;
[Link]("photosContainer").appendChild(card);
})
})
}
</script>
</head>
<body class="container-fluid">
<button onclick="FetchClick()" class="btn btn-primary mt-3 mb-3">Fetch Data</button>
<div class="mt-3 d-flex flex-wrap" id="photosContainer">
</div>
</body>
</html>
Sudhakar Sharma
[Link]
API Methods:
Ex:
var products = [
{
Name:"TV",
Category: "Electronics"
},
{
Name:"Nike Casuals",
Category: "Footwear"
},
{
Name: "Mobile",
Category: "Electronics",
}
]
[Link](function(product){
return [Link]=="Electronics";
}).map(function(product){
[Link]([Link] + "<br>");
})
(or)
for(var product of products)
{
if([Link]=="Electronics")
{
[Link]([Link] + "<br>");
}
}
(or)
for(var i=0; i<[Link]; i++)
{
if(products[i].Category=="Electronics")
{
[Link](products[i].Name + "<br>");
}
}
Ex: Shopper-Template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopper Template</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<script type="text/javascript">
function LoadCategories(){
fetch("[Link]
.then(function(res){
return [Link]();
})
.then(function(categories){
[Link]("all");
[Link](function(category){
var option = [Link]("option");
[Link] = [Link]();
[Link] = category;
[Link]("lstCategories").appendChild(option);
})
})
}
function LoadProducts(url){
[Link]("main").innerHTML = "";
fetch(url)
.then(function(res){
return [Link]();
})
.then(function(products){
[Link](function(product){
var card = [Link]("div");
[Link] = "card m-2 p-2";
[Link] = "200px";
[Link] = `
<img src=${[Link]} class="card-img-top" height="150">
<div class="card-header" style="height:140px; overflow:auto">
<p>${[Link]}</p>
</div>
<div class="card-body">
<dl>
<dt>Price</dt>
<dd>${[Link]}</dd>
<dt>Rating</dt>
<dd>${[Link]} <span class="bi bi-star-fill text-success"></span> [$
{[Link]}] </dd>
</dl>
</div>
<div class="card-footer">
<button class="btn btn-danger w-100">
<span class="bi bi-cart3"></span>
Add to Cart
</button>
</div>
`;
[Link]("main").appendChild(card);
})
})
}
function bodyload(){
LoadCategories();
LoadProducts("[Link]
}
function CategoryChanged(){
var categoryName = [Link]("lstCategories").value;
if(categoryName=="all"){
LoadProducts("[Link]
} else {
LoadProducts(`[Link]
}
}
function NavClick(){
LoadProducts("[Link]
}
</script>
<style>
a{
color:white;
text-decoration: none;
}
</style>
</head>
<body class="container-fluid" onload="bodyload()">
<header class="d-flex justify-content-between bg-dark text-white p-2">
<div><span class="h4">Shopper</span></div>
<div>
<span class="me-2"><a href="javascript:NavClick()">Home</a></span>
<span class="me-2">Electronics</span>
<span class="me-2">Men's Clothing</span>
<span class="me-2">Women's Clothing</span>
<span class="me-2">Jewelery</span>
</div>
<div>
<span class="bi bi-search me-2"></span>
<span class="bi bi-heart me-2"></span>
<span class="bi bi-person me-2"></span>
<button class="btn btn-light position-relative">
Your Cart<span class="bi bi-cart4"></span>
<span class="badge bg-danger position-absolute end-0 top-0 text-white rounded rounded-
circle" id="lblCount"></span>
</button>
</div>
</header>
<section class="mt-3 row">
<nav class="col-2">
<label class="form-label fw-bold">Select Category</label>
<div>
<select onchange="CategoryChanged()" class="form-select" id="lstCategories"></select>
</div>
</nav>
<main class="col-10 d-flex flex-wrap overflow-auto" style="height: 550px;">
</main>
</section>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Ex: Shopper-Template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopper Template</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<script type="text/javascript">
function LoadCategories(){
fetch("[Link]
.then(function(res){
return [Link]();
})
.then(function(categories){
[Link]("all");
[Link](function(category){
var option = [Link]("option");
[Link] = [Link]();
[Link] = category;
[Link]("lstCategories").appendChild(option);
})
})
}
function LoadProducts(url){
[Link]("main").innerHTML = "";
fetch(url)
.then(function(res){
return [Link]();
})
.then(function(products){
[Link](function(product){
var card = [Link]("div");
[Link] = "card m-2 p-2";
[Link] = "200px";
[Link] = `
<img src=${[Link]} class="card-img-top" height="150">
<div class="card-header" style="height:140px; overflow:auto">
<p>${[Link]}</p>
</div>
<div class="card-body">
<dl>
<dt>Price</dt>
<dd>${[Link]}</dd>
<dt>Rating</dt>
<dd>${[Link]} <span class="bi bi-star-fill text-success"></span> [$
{[Link]}] </dd>
</dl>
</div>
<div class="card-footer">
<button onclick="AddClick(${[Link]})" class="btn btn-danger w-100">
<span class="bi bi-cart3"></span>
Add to Cart
</button>
</div>
`;
[Link]("main").appendChild(card);
})
})
}
function bodyload(){
LoadCategories();
LoadProducts("[Link]
GetCount();
}
function CategoryChanged(){
var categoryName = [Link]("lstCategories").value;
if(categoryName=="all"){
LoadProducts("[Link]
} else {
LoadProducts(`[Link]
}
}
function NavClick(){
LoadProducts("[Link]
}
var cartItems = [];
function GetCount(){
[Link]("lblCount").innerHTML = [Link];
}
function AddClick(id){
fetch(`[Link]
.then(function(res){
return [Link]();
})
.then(function(product){
[Link](product);
alert(`${[Link]}\nAdded to Cart`);
GetCount();
})
}
function ShowCart(){
[Link]("tbody").innerHTML = "";
[Link](function(item){
var tr = [Link]("tr");
var tdTitle = [Link]("td");
var tdPrice = [Link]("td");
var tdImage = [Link]("td");
[Link]= [Link];
[Link] = [Link];
[Link] = `<img src=${[Link]} width="50" height="50">`;
[Link](tdTitle);
[Link](tdImage);
[Link](tdPrice);
[Link]("tbody").appendChild(tr);
})
}
</script>
<style>
a{
color:white;
text-decoration: none;
}
</style>
</head>
<body class="container-fluid" onload="bodyload()">
<header class="d-flex justify-content-between bg-dark text-white p-2">
<div><span class="h4">Shopper</span></div>
<div>
<span class="me-2"><a href="javascript:NavClick()">Home</a></span>
<span class="me-2">Electronics</span>
<span class="me-2">Men's Clothing</span>
<span class="me-2">Women's Clothing</span>
<span class="me-2">Jewelery</span>
</div>
<div>
<span class="bi bi-search me-2"></span>
<span class="bi bi-heart me-2"></span>
<span class="bi bi-person me-2"></span>
<button onclick="ShowCart()" class="btn btn-light position-relative" data-bs-target="#cart"
data-bs-toggle="modal">
Your Cart<span class="bi bi-cart4"></span>
<span class="badge bg-danger position-absolute end-0 top-0 text-white rounded rounded-
circle" id="lblCount"></span>
</button>
<div class="modal fade" id="cart">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-primary">
<h2>Your Cart Summary</h2>
</div>
<div class="modal-body">
<table class="table table-hover">
<thead>
<tr>
<th>Title</th>
<th>Preview</th>
<th>Price</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-bs-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
</div>
</header>
<section class="mt-3 row">
<nav class="col-2">
<label class="form-label fw-bold">Select Category</label>
<div>
<select onchange="CategoryChanged()" class="form-select" id="lstCategories"></select>
</div>
</nav>
<main class="col-10 d-flex flex-wrap overflow-auto" style="height: 550px;">
</main>
</section>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Map Type
- It is a key and value collection similar to object.
- The keys are of "any" type.
- The value are also "any" type.
- It provides lot of implicit methods used for manipulations.
- Hence it is faster than object. But it is schema less. [structure less]
Methods:
set() Add new key and value
get() Read a value using key.
has() To verify the availablity of key.
delete() To remove element using key
clear() To remove all keys and values
keys() It returns all keys
values() It returns all values
entries() It returns both keys and values
Syntax:
var topics = new Map();
[Link]("key", value);
[Link](key);
[Link](key);
[Link]()
[Link]
[Link]() etc...
Ex:
<script>
var topics = new Map();
[Link]("html", "It is a markup language");
[Link](2, "It configures styles");
Date Type
- JavaScript provides a Date() constructor to store and manipulate date type values.
Syntax:
var mfd = new Date(); => loads current date and time into memory
- JavaScript provides various methods to present date and time value. All date and time methods
return a number.
setHours()
setMinutes()
setSeconds()
setMilliSeconds()
setDate()
setMonth()
setFullYear()
toLocaleDateString()
toLocaleTimeString()
Ex:
<script>
var Name = "Samsung TV";
var Price = 45000.44;
var Mfd = new Date("2023-01-23 04:20:34.75");
var weekdays = ["Sunday","Monday","Tuesday", "Wed","Thu","Fri","Saturday"];
var months =
["Januay","Feb","Mar","Apr","May","June","July","August","Sept","Oct","Nov","Dec"];
[Link](7);
[Link](15);
[Link](`
Name=${Name}<br>
Price=${Price}<br>
Mfd=${weekdays[[Link]()]} ${[Link]()}, ${months[[Link]()]} $
{[Link]()}
`);
</script>
- setInterval() can load a function into memory and execute the function repeatedly at regular time
intervals.
Syntax:
setInterval(function(){}, interval);
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function Timer(){
var now = new Date();
[Link]("p").innerHTML = [Link]();
}
var clock;
function bodyload(){
clock = setInterval(Timer, 1000);
}
function StopClick(){
clearInterval(clock);
}
function StartClick(){
bodyload();
}
</script>
</head>
<body onload="bodyload()">
<p align="center"></p>
<div align="center">
<button onclick="StopClick()">Stop</button>
<button onclick="StartClick()">Start</button>
</div>
</body>
</html>
Debounce & Throttle
Timer Events
Sudhakar Sharma
Ex:
<script>
var now = new Date();
var hrs = [Link]();
if(hrs>=0 && hrs<=12){
[Link]("Good Morning");
} else if(hrs>12 && hrs<=16){
[Link]("Good Afternoon");
} else if(hrs>16 && hrs<=23) {
[Link]("Good Evening");
}
</script>
Debounce
Syntax:
setTimeout(function(){}, interval);
Syntax:
clearTimeout(functionReference);
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function f1(){
[Link]("p").innerHTML = "1";
}
function f2(){
[Link]("p").innerHTML = "2";
}
function f3(){
[Link]("p").innerHTML = "3";
}
var fun1, fun2, fun3;
function bodyload(){
fun1 = setTimeout(f1,2000);
fun2 = setTimeout(f2,5000);
fun3 = setTimeout(f3,10000);
}
function CancelClick(){
clearTimeout(fun2);
}
</script>
</head>
<body onload="bodyload()">
<button onclick="CancelClick()">Cancel 2nd Message</button>
<p align="center"></p>
</body>
</html>
Ex: Spinner
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interval Demo</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<style>
@keyframes ZoomIn {
from {
width: 10px;
height: 10px;
}
to {
width: 300px;
height: 400px;
}
}
</style>
<script>
var count = 0;
function LoadingStatus(){
var img = [Link]("img");
count++;
[Link]("lblStatus").innerHTML = `${count} % <br> Loading..`;
if(count==100){
[Link]("loadingContainer").[Link] = "none";
[Link]("imageContainer").[Link] = "block";
[Link] = "ZoomIn";
[Link] = "5s";
}
}
function LoadClick(){
setInterval(LoadingStatus,100);
[Link]("buttonContainer").[Link] = "none";
[Link]("loadingContainer").[Link] = "block";
}
</script>
</head>
<body class="container-fluid d-flex justify-content-center align-items-center" style="height:100vh">
<div>
<div id="buttonContainer">
<button class="btn btn-success" onclick="LoadClick()">Load Image</button>
</div>
<div id="loadingContainer" class="text-center" style="display: none;">
<div class="spinner-border"></div>
<div id="lblStatus"></div>
</div>
<div id="imageContainer" style="display: none;">
<img src="../public/images/[Link]">
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interval Demo</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
@keyframes ZoomIn {
from {
width: 10px;
height: 10px;
}
to {
width: 300px;
height: 400px;
}
}
progress {
width: 200px;
height: 30px;
}
</style>
<script>
var count = 0;
function LoadingStatus(){
var img = [Link]("img");
count++;
[Link]("progress").value = count;
[Link]("lblStatus").innerHTML = `${count} % <br> Loading..`;
if(count==100){
[Link]("loadingContainer").[Link] = "none";
[Link]("imageContainer").[Link] = "block";
[Link] = "ZoomIn";
[Link] = "5s";
}
}
function LoadClick(){
task = setInterval(LoadingStatus,100);
[Link]("buttonContainer").[Link] = "none";
[Link]("loadingContainer").[Link] = "block";
}
var task;
function PlayClick(){
task = setInterval(LoadingStatus,100);
}
function PauseClick(){
clearInterval(task);
[Link]("lblStatus").innerHTML = `${count} % <br> Paused..`;
}
</script>
</head>
<body class="container-fluid d-flex justify-content-center align-items-center" style="height:100vh">
<div>
<div id="buttonContainer">
<button class="btn btn-success" onclick="LoadClick()">Load Image</button>
</div>
<div id="loadingContainer" class="text-center" style="display: none;">
<progress min="1" max="100" value="1"></progress>
<div>
<button class="btn btn-success" onclick="PlayClick()"><span class="bi
bi-play"></span></button>
<button class="btn btn-danger" onclick="PauseClick()"><span class="bi
bi-pause"></span></button>
</div>
<div id="lblStatus"></div>
</div>
<div id="imageContainer" style="display: none;">
<img src="../public/images/[Link]">
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Slide Show</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<script>
var count = 0;
function LoadProduct(){
count++;
fetch(`[Link]
.then(function(res){
return [Link]();
})
.then(function(product){
[Link]("lblTitle").innerHTML = [Link];
[Link]("imgProduct").src = [Link];
})
}
function bodyload(){
LoadProduct();
}
var task;
function PlayClick(){
task = setInterval(LoadProduct,5000);
[Link]("lblStatus").innerHTML = "Slide Show - Started";
}
function PauseClick(){
clearInterval(task);
[Link]("lblStatus").innerHTML = "Slide Show - Paused";
}
var id=1;
function LoadProductById(id){
fetch(`[Link]
.then(function(res){
return [Link]();
})
.then(function(product){
[Link]("lblTitle").innerHTML = [Link];
[Link]("imgProduct").src = [Link];
})
}
function PreviousClick(){
id--;
LoadProductById(id);
}
function NextClick(){
id++;
LoadProductById(id);
}
</script>
</head>
<body class="container-fluid d-flex justify-content-center" onload="bodyload()">
<div class="card p-2 m-2 mt-4 w-50">
<div class="card-header text-center">
<p id="lblTitle"></p>
<p id="lblStatus"></p>
</div>
<div class="card-body">
<div class="row">
<div class="col-1">
<button class="btn" onclick="PreviousClick()"><span class="bi
bi-chevron-left"></span></button>
</div>
<div class="col-10">
<img id="imgProduct" width="100%" height="400">
</div>
<div class="col-1">
<button onclick="NextClick()" class="btn"><span class="bi
bi-chevron-right"></span></button>
</div>
</div>
</div>
<div class="card-footer text-center">
<button onclick="PlayClick()" class="btn btn-success bi bi-play-btn-fill"></button>
<button onclick="PauseClick()" class="btn btn-danger bi bi-pause-btn-fill"></button>
</div>
</div>
</body>
</html>
JavaScript Operators
Sudhakar Sharma
JavaScript Operators
- Operator is an object that evaluates a value using any expression.
- Operators are classified into various types based on the number operands they handle.
x + y; => x, y are operands
- Operators are classified into various types based on the value they return.
1. Arithematic Operators
2. Comparision Operators
3. Assignment Operators
4. Logical Operators
5. Bitwise Operators
6. Special Operators
Arithematic Operators
+ Addition
- Substraction
* Multiplication
/ Division
% Modulus Division
** Exponent
++ Increment
-- Decrement
Note: The addition operator "+" can handle operations with string type. It is used to
concat the value.
All other arithemantic operators returns NaN when used with string.
var result = ?
Method-1:
<script>
var values = [3, 2, 4, 7, 6, 9];
[Link](function(value){
if(value%2==0) {
[Link](value + "<br>");
}
})
</script>
Method-2:
<script>
var values = [3, 2, 4, 7, 6, 9];
for(var value of values){
if(value%2==0){
[Link](value + "<br>");
}
}
</script>
Method-3
<script>
var values = [3, 2, 4, 7, 6, 9];
var result = [Link](function(value){
return value%2==0;
});
[Link](result);
</script>
Ex: Print the total count of even numbers in a array. [Without array methods]
<script>
var values = [3, 2, 4, 7, 6, 9, 8];
var count = 0;
for(var value of values){
if(value%2==0){
count++;
}
}
[Link](`Total Count of Even Numbers : ${count}`);
</script>
Ex: Write a program to print total sum of even numbers in array. [Without Array Methods]
<script>
var values = [3, 2, 4, 7, 6, 9, 8];
var sum = 0;
for(var value of values){
if(value%2==0){
sum = sum + value;
}
}
[Link](`Total Count of Even Numbers : ${sum}`);
</script>
<script>
var values = [3, 2, 4, 7, 6, 9, 8];
var total = [Link](function(sum, value){
return sum + value;
});
[Link](`Total=${total}`);
</script>
Ex: Print the sum of even numbers from array using array methods.
<script>
var values = [3, 2, 4, 7, 6, 9, 8, 10];
var result = [Link](function(value){
return value%2==0;
}).reduce(function(total, num){
return total + num;
})
[Link](`Sum of Even numbers in Array : ${result}`);
</script>
<script>
var values = [3, 2, 4, 7, 6, 9, 8, 10];
var result = [Link](function(value){
return value%2!==0;
}).reduce(function(total, num){
return total + num;
})
[Link](`Sum of Even numbers in Array : ${result}`);
</script>
Comparision Operators
Sudhakar Sharma
Comparision Operators
== Equal
=== Identical Equal [It can compare only same type values]
!== Not Equal
!=== Not Identical
> Greater than
>= Greater than or equal
< Less than
<= Less than or equal
Syntax:
var a = "10";
var b = 10;
(a==b); => true
(a===b); => false
Forward Jump:
- In this decision making statements are executed only when condition is true.
- There is no alternative.
- It moves the next only when previous is true.
Syntax:
if (condition )
{
statements on true;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var userDetails = {
"Card": "4444555566667890",
"Cvv": "4567",
"Expiry": "2024"
}
function VerifyCard(){
var card = [Link]("txtCard").value;
if(card===[Link]){
[Link]("txtCvv").disabled = false;
}
}
function VerifyCvv(){
var cvv = [Link]("txtCvv").value;
if(cvv===[Link]){
[Link]("lstExpiry").disabled = false;
}
}
function VerifyExpiry(){
var expiry = [Link]("lstExpiry").value;
if(expiry===[Link]){
[Link]("btnPay").disabled = false;
}
}
</script>
</head>
<body>
<fieldset>
<legend>Payment Details</legend>
<dl>
<dt>Card Number</dt>
<dd><input type="text" id="txtCard" onblur="VerifyCard()"></dd>
<dt>Cvv</dt>
<dd><input type="text" id="txtCvv" onblur="VerifyCvv()" size="4" disabled></dd>
<dt>Expiry</dt>
<dd>
<select id="lstExpiry" disabled onchange="VerifyExpiry()">
<option>Select Expiry</option>
<option>2023</option>
<option>2024</option>
<option>2025</option>
</select>
</dd>
</dl>
<button disabled id="btnPay">Pay</button>
</fieldset>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var userDetails = {
"Card": "4444555566667890",
"Cvv": "4567",
"Expiry": "2024"
}
function VerifyCard(){
var card = [Link]("txtCard").value;
if(card===[Link]){
[Link]("txtCvv").disabled = false;
[Link]("cvvContainer").[Link] = "block";
}
}
function VerifyCvv(){
var cvv = [Link]("txtCvv").value;
if(cvv===[Link]){
[Link]("lstExpiry").disabled = false;
[Link]("expiryContainer").[Link] = "block";
}
}
function VerifyExpiry(){
var expiry = [Link]("lstExpiry").value;
if(expiry===[Link]){
[Link]("btnPay").disabled = false;
}
}
</script>
</head>
<body>
<fieldset>
<legend>Payment Details</legend>
<dl>
<dt>Card Number</dt>
<dd><input type="text" id="txtCard" onblur="VerifyCard()"></dd>
<div id="cvvContainer" style="display: none;">
<dt>Cvv</dt>
<dd><input type="text" id="txtCvv" onblur="VerifyCvv()" size="4" disabled></dd>
</div>
<div id="expiryContainer" style="display: none;">
<dt>Expiry</dt>
<dd>
<select id="lstExpiry" disabled onchange="VerifyExpiry()">
<option>Select Expiry</option>
<option>2023</option>
<option>2024</option>
<option>2025</option>
</select>
</dd>
</div>
</dl>
<button disabled id="btnPay">Pay</button>
</fieldset>
</body>
</html>
2. Simple Decision
- It provides single alternative.
- It is defined by using "if...else" clause.
Syntax:
if(condition)
{
statement on true;
}
else
{
statement on false;
}
Ex:
1. Add a new file into data folder
"[Link]"
[
{
"UserName":"john"
},
{
"UserName":"john12"
},
{
"UserName":"john_nit"
},
{
"UserName":"david"
}
]
2. HTML page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function VerifyUser(){
var username = [Link]("txtName").value;
var lblError = [Link]("lblError");
fetch("../data/[Link]")
.then(function(res){
return [Link]();
})
.then(function(users){
for(var user of users){
if([Link]===username){
[Link]= "User Name Taken - Try Another".fontcolor('red');
break;
} else {
[Link] = "User Name Available".fontcolor('green');
}
}
})
}
</script>
</head>
<body>
<fieldset>
<legend>Register User</legend>
<dl>
<dt>User Name</dt>
<dd><input type="text" id="txtName" onkeyup="VerifyUser()"></dd>
<dd id="lblError"></dd>
</dl>
</fieldset>
</body>
</html>
3. Multiple Choices
- It is a decision making approach where more than one alternative is provided.
- It is configured with "if...else if ... else".
Syntax:
if(condition-1)
{
statement on condition-1 true;
}
else if(condition-2)
{
statement on condition-2 true;
}
else
{
statement on all conditions false;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<script>
var userDetails = {
"Email": "john11@[Link]",
"Mobile": "+919876543211",
"Password": "john@123"
}
var flag = "";
function ContinueClick(){
var user = [Link]("txtUser").value;
var pwdContainer = [Link]("pwdContainer");
var userContainer = [Link]("userContainer");
if(user===[Link]) {
flag = `Login success with your Email - Verification Code sent to email ${user}`;
[Link] = "block";
[Link] = "none";
} else if(user===[Link]) {
flag = `Login Success with Mobile - OTP Sent to your mobile ${user}`;
[Link] = "block";
[Link] = "none";
} else {
[Link]("userError").innerHTML = `${user} Not Avaialble`;
}
}
function LoginClick(){
var pwd = [Link]("txtPwd").value;
if(pwd===[Link]){
[Link](`<h2>${flag}</h2>`);
} else {
[Link]("pwdError").innerHTML = "Invalid Password";
}
}
</script>
</head>
<body class="container-fluid d-flex justify-content-center align-items-center" style="height: 100vh;">
<div>
<h2>Amazon Login</h2>
<div id="userContainer">
<label class="form-label fw-bold"> Email address or mobile phone number</label>
<div>
<input type="text" id="txtUser" class="form-control">
<div id="userError" class="text-danger"></div>
</div>
<div class="mt-3">
<button class="btn btn-warning w-100" onclick="ContinueClick()">Continue</button>
</div>
</div>
<div id="pwdContainer" style="display: none;">
<label class="form-label fw-bold">Your Password</label>
<div>
<input type="password" class="form-control" id="txtPwd">
<div id="pwdError" class="text-danger"></div>
</div>
<div class="mt-3">
<button class="btn btn-warning w-100" onclick="LoginClick()">Login</button>
</div>
</div>
</div>
</body>
</html>
Sudhakar Sharma
- forward jump
- simple decision
- multiple choices
&& Logical AND [returns true when all conditions are true]
|| Logical OR [returns true when any one condition is true]
Syntax:
if(card==="4444" && cvv==="332" && expiry==="2024")
{
success..
}
else
{
Invalid; ?
}
- Always developer have to prefer using multi level conditions to handle invidual expressions.
Syntax:
if (condition-1 )
{
if(condition-2)
{
statements when both conditions are true;
}
else
{
statements when condition 2 is false;
}
}
else
{
statement on condition 1 false;
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var userDetails = {
"Card": "4444555566667890",
"Cvv": "4567",
"Expiry": "2024"
}
function PayClick(){
var card =[Link]("txtCard").value;
var cvv = [Link]("txtCvv").value;
var expiry = [Link]("lstExpiry").value;
var msg = [Link]("msg");
if(card===[Link])
{
if(cvv===[Link]){
if(expiry===[Link]){
[Link]("Payment Success..");
} else {
[Link] = "Invalid Expiry";
}
} else {
[Link] = "Invalid Cvv";
}
}
else
{
[Link] = "Invalid Card Number";
}
}
</script>
</head>
<body>
<fieldset>
<legend>Payment Details</legend>
<dl>
<dt>Card Number</dt>
<dd><input type="text" id="txtCard"></dd>
<div id="cvvContainer">
<dt>Cvv</dt>
<dd><input type="text" id="txtCvv" size="4" ></dd>
</div>
<div id="expiryContainer" >
<dt>Expiry</dt>
<dd>
<select id="lstExpiry">
<option>Select Expiry</option>
<option>2023</option>
<option>2024</option>
<option>2025</option>
</select>
</dd>
</div>
</dl>
<button id="btnPay" onclick="PayClick()">Pay</button>
<p align="center" id="msg" style="color:red;"></p>
</fieldset>
</body>
</html>
Program-1: Check the value range and return in-range or out of range result.
Startup Code:
function findRange(value, min, max)
{
}
Solution Code:
<script>
function findRange(value, min, max){
if(value>=min && value<=max){
[Link](`Your value ${value} is in range of ${min} - ${max}`);
} else {
[Link](`Your value ${value} is not in range of ${min} - ${max}`);
}
}
findRange(25,11,20);
</script>
Startup Code:
function findGreatest(a, b, c)
{
}
Solution Code:
<script>
function findGreatest(a, b, c)
{
if(a>b && a>c){
[Link](`a=${a} is greater than b=${b} & c=${c}`);
} else if(b>c) {
[Link](`b=${b} is greater than a=${a} & c=${c}`);
} else {
[Link](`c=${c} is greater than a=${a} & b=${b}`);
}
}
findGreatest(120,213,46);
</script>
Problem-3: Read multiple values from a function and return the values are for a triangle or for a
square or form polygon
Startup Code:
function findShape(values) => array type input
{
}
<script>
function findShape(values){
if([Link]<3){
[Link]("Please provide 3 or more values");
} else {
if([Link]===3){
[Link]("You entered values for Triangle");
} else if([Link]===4) {
[Link]("You entered values for Square or Rectangle");
} else if([Link]>=5) {
[Link]("You entered values for Ploygon");
}
}
}
findShape([10,20,10,40,50]);
</script>
Problem-4: Write a program to find the values are for a square or rectangle.
Startup Code:
function findShape(side1, side2, side3, side4)
{
Solution Code:
<script>
function findShape(side1, side2, side3, side4){
if(side1==side2 && side2==side3 && side3==side4){
[Link]("Square");
} else {
[Link]("Rectangle");
}
}
findShape(10, 10, 10, 10);
</script>
Startup Code:
findTriangleType(side1, side2, side3)
{
}
Switch Case
Sudhakar Sharma
Note: It there are too many choices for an application then better avoid "if..else if".
You can use "switch" selector.
Switch
- Switch is used to interrupt the flow of electronics.
- There are various types of switches.
toogle switch
push button
joy stick
selector etc..
- Switch selector provides multiple cases, which are invoked individually.
- It can select any specific case without invoking other cases.
- It there are many choices better to use "switch".
Syntax:
switch(value | expression)
{
case value|expression:
statements to execute;
jump;
default:
statement to execute as clause;
jump;
}
Ex:
<script>
var n = parseInt(prompt("Enter Number"));
switch(n)
{
case 1:
[Link]("One");
break;
case 2:
[Link]("Two");
break;
case 3:
[Link]("Three");
break;
case 4:
[Link]("Four");
break;
default:
[Link]("Please enter 1 to 4 only");
break;
}
</script>
FAQ's:
1. Can we define a switch without default?
A. Yes.
case 1:
case 2:
[Link]("You entered 1 or 2");
break;
Ex:
<script>
var choice = prompt("Enter Choice","y/n");
switch(choice){
case "y":
case "Y":
[Link]("You selected Yes to continue");
break;
case "n":
case "N":
[Link]("You select No to stop.");
break;
default:
[Link]("Please enter y or n");
break;
}
</script>
var n = 4;
n is between 1 to 10
n is between 11 to 20
please enter 1 to 20 only.
Ex:
<script>
var n = parseInt(prompt("Enter Number"));
switch(true)
{
case (n>=1 && n<=10):
[Link](`Your value ${n} is between 1 to 10`);
break;
case (n>=11 && n<=20):
[Link](`Your value ${n} is between 11 to 20`);
break;
default:
[Link](`Your value ${n} must be between 1 to 20`);
break;
}
</script>
Amount : 450
[ four hundred fifty ]
Assignment Operators
Sudhakar Sharma
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
select {
width: 150px;
}
</style>
<script>
var categories = ["Select a Category", "Electronics", "Footwear"];
var electronics = ["Select Electronics", "Televisions", "Mobiles"];
var footwear = ["Select Footwear", "Boots", "Casuals", "Sneakers"];
var products = [];
function LoadCategories(){
[Link](function(category){
var option = [Link]("option");
[Link] = category;
[Link] = category;
[Link]("lstCategories").appendChild(option);
})
}
function LoadProducts(){
[Link]("lstProducts").innerHTML="";
[Link](function(product){
var option = [Link]("option");
[Link] = product;
[Link] = product;
[Link]("lstProducts").appendChild(option);
})
}
function bodyload(){
LoadCategories();
}
function CategoryChanged(){
var categoryName = [Link]("lstCategories").value;
switch(categoryName)
{
case "Electronics":
products = electronics;
LoadProducts();
break;
case "Footwear":
products = footwear;
LoadProducts();
break;
default:
products = ["Please Select Category"];
LoadProducts();
break;
}
}
</script>
</head>
<body onload="bodyload()">
<dl>
<dt>Select Category</dt>
<dd>
<select id="lstCategories" onchange="CategoryChanged()"></select>
</dd>
<dt>Select Product</dt>
<dd>
<select id="lstProducts"></select>
</dd>
</dl>
</body>
</html>
Summary
- Comparision Operators
- Selection Statements
if, else, switch, case, default
Logical Operators
- "&&" combine multiple expressions and return true when all expressions evaluate to true.
- "||" combine multiple expressions and reutrn true when any one of the expression is true.
Assignment Operators
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KFC</title>
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<script type="text/javascript">
function OrderClick(){
[Link]("lblCustomer").innerHTML =
[Link]("txtName").value;
[Link]("lblMobile").innerHTML =
[Link]("txtMobile").value;
var imgMeal = [Link]("imgMeal");
var mealName="";
var mealCost = 0;
if([Link]){
mealName = [Link];
mealCost = 120;
[Link] = "../public/images/[Link]";
}
if([Link]){
mealName = [Link];
mealCost = 90;
[Link] = "../public/images/[Link]";
}
if([Link]) {
adOnCost = 40;
adonName += [Link] + "<br>";
mealCost = mealCost + adOnCost;
}
if([Link]){
adOnCost = 70;
adonName += [Link] + "<br>";
mealCost = mealCost + adOnCost;
}
[Link]("lblMeal").innerHTML = mealName;
[Link]("lblAdOn").innerHTML = adonName;
[Link]("lblTotal").innerHTML = `₹ ${mealCost}`;
}
</script>
</head>
<body class="container-fluid">
<header class="mt-1">
<img src="../public/images/[Link]" width="100%" height="150">
</header>
<section>
<div class="accordion" id="kfc">
<!-- Customer Item -->
<div class="accordion-item">
<div class="accordion-header">
<button data-bs-toggle="collapse" data-bs-target="#customer" class="btn btn-danger w-
100">Customer Details</button>
</div>
<div class="accordion-collapse collapse show" id="customer" data-bs-parent="#kfc">
<div class="accordion-body bg-danger text-white mt-2">
<dl>
<dt>Customer Name</dt>
<dd><input type="text" id="txtName" class="form-control"></dd>
<dt>Mobile</dt>
<dd><input type="text" id="txtMobile" class="form-control"></dd>
</dl>
</div>
</div>
</div>
</div>
</section>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/bootstrap/dist/js/[Link]"></script>
</body>
</html>
Sudhakar Sharma
•
Aug 23, 2023
Special Operators
Syntax:
(condition) ? true : false
Syntax:
var now = new Date();
var values = new Array();
Syntax:
var product = {Name:"TV", Price: 45600.44};
delete [Link];
Syntax:
"Price" in product => true | false
Syntax:
var price = 45000;
typeof price; => number
Syntax:
var values = new Array();
"values" instanceof Array; => true
"values" instanceof Employee; => false
JavaScript Statements
- Statements are used in computer programming to control the execution flow.
- Statements are classified into various types
1. Selection Statements
if, else, switch, case, default
3. Iteration Statements
for..in, for..of
4. Jump Statements
break, return, continue
Looping Control
- Looping is the process of executing a set of statements repeatedly based on given condition.
- Loops are created by using
a) for
b) while
c) do while
- Every loop contains initialization, condition and counter.
Syntax:
for(initialization; condition; counter)
{
EX:
for(var i = 1; i<=10; i++)
{
[Link](i + "<br>");
}
Startup Code:
function PrintTable(n)
{
PrintTable(5) =>
5 x 1 =5
5 x 2 = 10
.....
5 x 10 = 50
Solution:
<script>
function PrintTable(n){
for(var i = 1; i<=10; i++){
[Link](`${n} x ${i} = ${n*i}<br>`);
}
}
PrintTable(parseInt(prompt("Enter Number")));
</script>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var menu = [
{Category:"Electronics", Products:["Mobiles", "Televisions"]},
{Category:"Footwear", Products:["Boots", "Casuals", "Sneakers"]}
];
function bodyload(){
for(var i=0; i<[Link]; i++){
var olLi = [Link]("li");
[Link] = menu[i].Category;
for(var j=0; j< menu[i].[Link]; j++){
var ul = [Link]("ul");
var ulLi = [Link]("li");
[Link] = menu[i].Products[j];
[Link](ulLi);
[Link](ul);
[Link]("ol").appendChild(olLi);
}
}
}
</script>
</head>
<body onload="bodyload()">
<ol>
</ol>
</body>
</html>
Ex: Iterators
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var menu = [
{Category:"Electronics", Products:["Mobiles", "Televisions"]},
{Category:"Footwear", Products:["Boots", "Casuals", "Sneakers"]}
];
function bodyload(){
[Link](function(item){
var olLi = [Link]("li");
[Link] = [Link];
[Link](function(product){
var ul = [Link]("ul");
var ulLi = [Link]("li");
[Link] = product;
[Link](ulLi);
[Link](ul);
[Link]("ol").appendChild(olLi);
})
})
}
</script>
</head>
<body onload="bodyload()">
<ol>
</ol>
</body>
</html>
10 20 30
40 50 60
Solution:
<script>
var values = [[10, 20, 30], [40, 50, 60]];
for(var i=0; i<[Link]; i++){
for(var j=0; j<values[i].length; j++){
[Link](`${values[i][j]} `)
}
[Link]("<br><br>");
}
</script>
*
* *
* * *
* * * *
* * * * *
Startup Code:
function PrintPattern(n)
{
}
Solution Code:
<script>
function PrintPattern(n){
for(var i=1; i<=n; i++){
for(var j=1; j<=i; j++){
[Link]("* ");
}
[Link]("<br>");
}
}
PrintPattern(parseInt(prompt("Enter Number")));
</script>
*
* *
* * *
* *
*
Sudhakar Sharma
Syntax:
var i = 1;
while(i<=10)
{
[Link](i + "<br>");
i++;
}
The do While:
- It is same as while loop but make sures that the statements execute atleast once
even when condition is false.
Syntax:
var i = 1;
do
{
[Link](i + "<br>");
i++;
} while(i<=10);
Iteration Statements
- Iteration doesn't require initialization, condition and counter.
- Iterations are created by using
a) for..in
b) for..of
Jump Statements
1. break
2. return
3. continue
Ex:
<script>
for(var i=1; i<=10; i++){
if(i==5 || i==8){
continue;
}
[Link](i + "<br>");
}
</script>
Ex:
<script>
fetch("[Link]
.then(function(res){
return [Link]();
})
.then(function(products){
for(var product of products){
if([Link]==="electronics" || [Link]==="jewelery"){
continue;
}
[Link](`${[Link]} - <b>${[Link]}</b><br>`);
}
})
</script>
Ex:
<script>
try {
var a = parseInt(prompt("Enter A value"));
var b = parseInt(prompt("Enter B Value"));
if(b==0){
throw "Can't Divide By Zero<br>";
}
if(b>a) {
throw "Number too large to divide<br>";
}
var c = a / b;
[Link](`Division=${c}<br>`);
}
catch(exp){
[Link](exp);
}
finally {
[Link](`Program End`);
}
</script>
Summary
- Selection
- Looping
- Iteration
- Jump
- Exception Handling
JavaScript Functions
Function Configuration:
- JavaScript functions can be configured in 2 ways
a) Function Declaration
b) Function Expression
Syntax: Declaration
function Print()
{
}
Syntax: Expression
Print = function() { };
- Function Declaration allocates memory for function and handle specific operation defined in the
definition of function.
- Function expression can change the functionality according to state and situation.
Ex:
<script>
var password = prompt("Enter Password");
var result = function() {};
if(password=="admin"){
result = function(){
[Link]("Login Success");
}
} else {
result = function(){
[Link]("Invalid Login - Try Again");
}
}
result();
</script>
( function() { } )();
Ex:
(function(){
[Link]("Hello");
})();
Syntax:
function Name(params)
{
Function Parameters:
- A function can be parameter less or parameterized.
- A parameter is used to modify the function.
Syntax:
function Name(param) => param is a formal parameter
{
Ex:
<script>
function PrintNumbers(howMany){
for(var i=1; i<=howMany; i++){
[Link](i + "<br>");
}
}
PrintNumbers(4);
PrintNumbers(9);
</script>
Syntax:
function Name(x)
{
}
Name(number)
Name(string)
Name(boolean)
Name([ ])
Name({ })
Name(new Date())
Name(new Map())
Ex:
<script>
function Details(values){
for(var item of values){
[Link](item + "<br>");
}
}
function Product(prod){
[Link](`Name=${[Link]}<br>Price=${[Link]}`);
}
Details([10, 20, 30]);
Product({Name:"Samsung TV", Price: 45000.33});
</script>
Functions continued..
Sudhakar Sharma
JavaScript Functions
- Function Declaration
- Function Expression
- Anonymous Function
- IIFE Pattern
- Function Parameters
a) Actual Parameters
b) Formal Parameters
Multiple Parameters
- A function can have mutliple parameters.
- Every parameter is required. [Mandatory to pass value]
- Every parameter have ordered dependency.
- If you want to skip any parameter, then you have configure as undefined and write the logic for
undefined value.
Ex:
<script>
function Details(id, name, price, stock){
if(price){
[Link](`
Id=${id} <br>
Name=${name}<br>
Price=${price}<br>
Stock=${stock}
`);
} else {
[Link](`
Id=${id} <br>
Name=${name}<br>
Stock=${stock}
`);
}
}
Details(1, "TV", 450000.44 , true);
</script>
Rest Parameters
- A single rest parameter can allow multiple values.
- It is an array type parameter.
- It is configured using "..." and parameter name.
Syntax:
function Name(...param) => param[]
{
}
- You have to define as last parameter, as it can read value upto end.
Ex:
<script>
function Details(title,...product){
var [id, name, price, stock] = product;
[Link](`
<h3>${title}</h3>
Id=${id} <br>
Name=${name}<br>
Price=${price}<br>
Stock=${stock}
`)
}
Details("Product Details",1, "TV", 45000.44 , true);
</script>
Spread Parameters
- You can spread single actual value into multiple parameters.
- The actual value must be only array type.
Syntax:
function Name(p1, p2, p3)
{
}
Ex:
<script>
function Details(id, name, price)
{
[Link](`Id=${id}<br>Name=${name}<br>Price=${price}`);
}
var product = [1, "TV", 46000.33];
Details(...product);
</script>
Syntax:
function Name()
{
return value;
}
Name() = value;
Syntax:
fetch(url)
.then(function(res){
return [Link]()
})
.then(function(data){
})
Ex:
<script>
function Addition(a, b)
{
return a + b;
}
function Print(){
[Link](`Addition=${Addition(10,30)}`);
}
Print();
</script>
Ex:
<script>
function Categories(){
return ["All", "Kids", "Women", "Men"];
}
Categories().map(function(category){
[Link](category + "<br>");
})
</script>
Ex: Captcha
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function Captcha(){
var a = [Link]() * 10;
var b = [Link]() * 10;
var c = [Link]() * 10;
var d = [Link]() * 10;
var e = [Link]() * 10;
var f = [Link]() * 10;
return `${[Link](a)} ${[Link](b)} ${[Link](c)} ${[Link](d)} $
{[Link](e)}`;
}
function bodyload(){
[Link]("code").innerHTML = Captcha();
}
</script>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<style>
dt {
font-weight: bold;
margin-top: 5px;
}
</style>
</head>
<body onload="bodyload()">
<dl>
<dt>User Id</dt>
<dd><input type="text"></dd>
<dt>Password</dt>
<dd><input type="password"></dd>
<dt>Verify Code <button onclick="bodyload()" class="bi bi-arrow-clockwise"></button></dt>
<dd id="code"></dd>
</dl>
<button>Login</button>
</body>
</html>
Functions continue..
Sudhakar Sharma
•
Aug 28, 2023
Function Closure
- Closure is a technqiue where the members of outer function are accessible to inner function.
- Every function by default have a closure.
- It is the mechanism of function used for its scope members.
- To access the member of inner function in outer function, you have to use the "return" technique.
Syntax:
function outer()
{
...members...
function inner()
{
//can use outer members..
return values;
}
// can access inner return values
}
Ex:
<script>
function Outer(){
var x = 10;
function Inner(){
var y = 20;
var z = x + y;
return z;
}
[Link]("addition=" + Inner());
}
Outer();
</script>
Function Recursion
- It is the process of accessing a function with in the scope of same function.
Syntax:
function f1()
{
f1();
}
- It allows to create batch operations.
- It repeats the statements without using loops and iterators.
Startup Code:
function Factorial(n)
{
}
Factorial(5) = 120 => 5 x 4 x 3 x 2 x 1
Solution Code:
<script>
function Factorial(n){
var result = 1;
for(var i=n; i>=1; i--){
result = result * i;
}
[Link]("Factorial = " + result);
}
Factorial(6);
</script>
<script>
function Factorial(n){
if(n==0){
return 1;
} else {
return n * Factorial(n-1);
}
}
[Link](`Factorial of 5 =` + Factorial(6));
</script>
Startup Code :
function Table(5)
{
}
5x1=5
5 x 2 = 10
Function Generator
- A function generator is used in iterations.
- It is used to create iterations, which doesn't require initialization, condition and counter.
- Every generator function implicitly manages initialization, condition and counter.
- It comprises of following methods and properties
Syntax:
function* Name()
{
yeild value;
}
Ex:
<script>
function* PrintNumbers(){
yield 10;
yield 20;
yield 30;
yield 40;
}
var obj = PrintNumbers();
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
</script>
Sudhakar Sharma
Arrow Functions
function Name()
{
}
Ex:
<script>
function Addition(a, b){
return a + b;
}
var mul = (a,b) => a * b;
[Link](`Addition=${Addition(10,20)}<br>Multiply=${mul(2,6)}`);
</script>
Ex:
<script>
var hello = (uname,age) => [Link](`Hello ! ${uname} your age ${age}`);
hello("John",22);
</script>
Ex:
<script>
var categories = ["All", "Fashion", "Footwear"];
[Link](category=>{
[Link](category + "<br>");
})
/*
[Link](function(category){
})
*/
</script>
Ex:
<script>
fetch("[Link]
.then(response=> [Link]())
.then(products=>{
[Link](product=>{
[Link]([Link] + "<br>");
})
})
</script>
CallBacks
- It is a technique of configuring functions where the functionality is defined according to state and
situation.
- Callback uses synchronous technique.
- It block the other actions while executing the specified function.
Syntax:
function Name(f1, f2)
{
}
Name( ()=>{ }, ()=> { } ); It have 2 callbacks
Ex:
<script>
function FetchData(url,success,failure){
if(url==="[Link]
success();
} else {
failure();
}
}
FetchData(prompt("Enter Url"), ()=>{
[Link]("Data Fetched Successfully..")
},()=>{
[Link]("Invalid Url : Unable to Fetch Data");
})
</script>
JavaScript Promise
Syntax:
var obj = new Promise((resolve, reject)=>{
if(condition)
{
resolve(value);
} else {
reject(value);
}
})
- You can access the result and execute a promise using are reference object or directly by using
reference name.
- It returns
then() => on resolve
catch() => on rejected
finally() => every time
Syntax:
[Link](msg => { }).catch(msg => { }).finally(()=> { })
Ex:
<script>
var FetchData = new Promise((resolve, reject)=>{
var url = prompt("Enter Url");
if(url==="[Link]
resolve(`Success: Data Fetched successfully..`);
} else {
reject(`Error: Unable to fetch data`);
}
})
[Link]((msg)=>{
[Link](msg);
}).catch((msg)=>{
[Link](msg);
})
</script>
Summary
- Variables
- Data Types
- Operators
- Statements
- Functions
JavaScript OOP
1. POPS
2. OBPS
3. OOPS
POPS:
- Process Oriented Programming System
- It is light weight
- It uses less memory
- It is faster
- It supports low level features that can directly interact with hardware.
Ex: C, Pascal
OBPS
- Object Based Programming System
- It supports code reusability and separation
- It have dynamic memory
- It have limited extensibility.
- Extensibility Issues
- Code level security issues
- No dynamic polymorphism.
- No contracts and abstraction
OOPS
- Object Oriented Programming System
- It supports reusability
- It supports extensibility
- It supports code level security
- It have contract and abstraction
Note: JavaScript is not an OOP language, it supports only few features of OOP.
Evolution of OOP:
- In early 1960's Alan Kay introduced "Object" into computer programming.
- In 1967 Johan Olay, Kristian Nygaard developed Object Oriented Programing with a language called
"SIMULA".
- SIMULA introduced code reusability.
- In 1970's "Trygve" introduced code separation.
- Tryge introduced a framework called "MVC" [Model View Controller]
- MVC was formulated with a language class "Small Talk".
- In 1975 C++
- In 1990 Java
- In 2003 C#
Sudhakar Sharma
Modules
- A module is a set of variables, functions and classes.
- Every JavaScript file is considered as a module.
- You can build a library using modules.
- So that you can reuse your code across projects or pages in a project.
- A module allows to use any library without linking the JavaScript file.
- In order to use modules in any JavaScript project you must have a module system installed.
- There are various module systems for JavaScript
a) Common JS
b) Require JS
c) UMD [Universal Module Distribution]
d) AMD [Asynchronous Module Distribution] etc..
- If you are using JavaScript in browser, then the browser engine have a default module system called
"ES Module".
- You have to enable ES Module system by defining the script type as "Module".
<script type="module">
</script>
- Every member that you define a module is not accessible outside module.
- You have to mark it as "export".
- Every module system will not use "import" statement, there are various other methods like
"require()".
[Link]();
Syntax:
export default function Name()
{
}
Ex:
1. Add a new folder into project by name "library".
2. Add subfolder by name "modules" into library.
3. Add following JS files
"[Link]"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Module Demo</title>
<script type="module">
import { Hello, Welcome } from '../library/modules/[Link]';
import Multiply, { Addition } from '../library/modules/[Link]';
Class in OOP
- In computer programming class is a program template.
- A program template comprises of pre-defined data and logic, which you can import and implement
by customizing according your requirements.
- A class is reffered as "Entity" when it is mapping to business requirements.
- A class is reffered as "Model" when it is mapping to data requirements.
- A class acts as a blue-print for reusing the code.
- Hence class is a model, entity and blue-print in general terms.
Configuring a Class:
- There are 2 methods for configuring a class
a) Class Declaration
b) Class Expression
Syntax: Expression
var Product = class {
Syntax: Declaration
class Product
{
}
Class Members:
- Every JavaScript class can have only following members
a) Property
b) Accessor
c) Constructor
d) Method
Sudhakar Sharma
Property
- Property is a reference in class where we can store data.
- Property is mutable.
- JavaScript properties can have just a reference name without and access restriction.
Syntax:
class Name
{
PropertyName = value;
}
Syntax:
class Product
{
Name = "Samsung TV";
Price = 45000.44;
Stock = true;
Cities = ["Delhi", "Hyd"];
Rating = { rate: 3.5, count: 4500 };
}
- The properties of class are accessible inside class using "this" keyword and outside class by using
instance of class.
Syntax:
let ob = new Product(); // valid => () refers tj o constructor
let obj = new Product; // valid
Ex:
<script>
class Product
{
Name = "Samsung TV";
Cities = ["Delhi","Hyd"];
Rating = {rate: 4.5, count:4560}
}
let obj = new Product;
[Link] = prompt("Enter Name");
[Link](`Name=${[Link]}<br>Cities=${[Link]()}<br>Rating=$
{[Link]}`);
</script>
Accessors
Syntax:
set aliasName(newValue) => 10
{
[Link] = newValue; => 10
}
aliasName = value|10;
Note: Accessors are used to give a fine grained control over property.
Ex:
<script>
var userName = prompt("Enter Your Name");
var userRole = prompt("Enter Your Role","admin|customer|manager");
var productname = prompt("Enter Product Name");
class Product
{
_productName;
get ProductName(){
return this._productName;
}
set ProductName(newValue){
if(userRole==="admin"){
this._productName = newValue;
} else {
[Link](`<code>Hello ! ${userName} your role ${userRole} is not authorized to set
product name</code>`.fontcolor('red'));
}
}
}
let obj = new Product;
[Link] = productname;
if([Link]){
[Link](`Name=${[Link]}`);
}
</script>
Ex:
<script>
class Product
{
Name = "Samsung TV";
Rating = {
CustomerRating: {rate:3.5, count:5600},
VendorRating: {
DirectVendor: {rate:4.2, count:3},
IndirectVendor: {rate:4.5, count:56}
}
}
get DirectVendorRating(){
return [Link];
}
set DirectVendorRating(newRating){
[Link] = newRating;
}
}
var obj = new Product;
[Link] = prompt("Enter Rating");!
[Link](`Direct Vendor Rating : ${[Link]}`);
</script>
Methods
- A method is used to configure functionality for class.
- A method can be configured only in a class.
- Usually a method is void type. However JavaScript methods can return a value.
- Method is mutable, where as function is immutable.
- A function is not allowed as class member.
Syntax: void
class Name
{
MethodName(params)
{
}
}
Sudhakar Sharma
•
Sep 1, 2023
Class Components
- Property
- Accessor
- Method
Ex:
<script>
class Product
{
Name = "Samsung TV";
Price = 45000.33;
Qty = 0;
Total(){
return [Link] * [Link];
}
Print(){
[Link](`Name=${[Link]}<br>Price=${[Link]}<br>Qty=${[Link]}<br>Total=$
{[Link]()}`);
}
}
let obj = new Product;
[Link] = parseInt(prompt("Enter Quantity"));
[Link]();
</script>
Constructor
- It is a special type of sub-routine defined in class, which is used for instantiation.
- Instantiation is the process of creating an object for class.
- Every class have a default constructor.
- You can create an explicit constructor to define actions, which are performed at the time of creating
object.
- Constructor is same like a method, but it is defined with constructor keyword and it is anonymous.
Syntax:
class Demo
{
constructor() {
}
}
Syntax:
var obj = new className(value); => (value) constructor with value
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
class Database
{
constructor(dbName){
[Link](`Connected with ${dbName} database <br>`);
}
Insert(){
[Link]("Record Inserted");
}
Update(){
[Link]("Record Updated");
}
Delete(){
[Link]("Record Deleted");
}
}
function InsertClick(){
let obj = new Database([Link]("select").value);
[Link]();
}
function UpdateClick(){
let obj = new Database([Link]("select").value);
[Link]();
}
function DeleteClick(){
let obj = new Database([Link]("select").value);
[Link]();
}
</script>
</head>
<body>
<select>
<option>Select Database</option>
<option>Oracle</option>
<option>MySql</option>
<option>MongoDB</option>
</select>
<button onclick="InsertClick()">Insert</button>
<button onclick="UpdateClick()">Update</button>
<button onclick="DeleteClick()">Delete</button>
</body>
</html>
- Code extensibility is a technique where we can extend the existing logic without modifying the
current context.
a) Aggregation
b) Inheritance
Aggregation:
- It is the process of accessing members of one class in another class without creating any
relationship between classes.
- It uses object-to-object communication, which is known as "Has-A-Relation".
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
class HDFCBank_Version1
{
Personal = "Personal Banking Services <br>";
NRI = "NRI Banking Services <br>";
Print(){
[Link](`${[Link]}<br>${[Link]}<br>`);
}
}
class HDFCBank_Version2
{
Loans = "Personal & Car Loans<br>";
Print(){
let obj = new HDFCBank_Version1();
[Link]();
[Link](`${[Link]}<br>`);
}
}
class HDFCBank_Version3
{
AGRI = "Govt. Bank Schemes<br>";
Print(){
let obj = new HDFCBank_Version2();
[Link]();
[Link](`${[Link]}<br>`);
}
}
function InstallClick(){
var version = [Link]("select").value;
switch(version)
{
case "ver1":
let obj1 = new HDFCBank_Version1();
[Link]("<h2>Version-1 Installed</h2>");
[Link]();
break;
case "ver2":
let obj2 = new HDFCBank_Version2();
[Link]("<h2>Version-2 Installed</h2>");
[Link]();
break;
case "ver3":
let obj3 = new HDFCBank_Version3();
[Link]("<h2>Version-3 Installed</h2>");
[Link]();
break;
default:
[Link]("Please Select a Version to Install");
break;
}
}
</script>
</head>
<body>
<fieldset>
<legend>HDF Bank Application</legend>
<select>
<option value="-1">Select Version</option>
<option value="ver1">Version-1 2022</option>
<option value="ver2">Version-2 2023 (May)</option>
<option value="ver3">Version-3 2023 (Aug)</option>
</select>
<button onclick="InstallClick()">Install</button>
</fieldset>
</body>
</html>
Inheritance:
- It is a technique of reusing the extending the code by configuring relationship between classes.
- It is reffered as "Is-A-Relation".
- You can create a new class that "extends" existing class
Syntax:
class A
{
}
class B extends A
{
}
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
class HDFCBank_Version1
{
Personal = "Personal Banking Services <br>";
NRI = "NRI Banking Services <br>";
Print(){
[Link](`${[Link]}<br>${[Link]}<br>`);
}
}
class HDFCBank_Version2 extends HDFCBank_Version1
{
Loans = "Personal & Car Loans<br>";
Print(){
[Link]();
[Link](`${[Link]}<br>`);
}
}
class HDFCBank_Version3 extends HDFCBank_Version2
{
AGRI = "Govt. Bank Schemes<br>";
Print(){
[Link]();
[Link](`${[Link]}<br>`);
}
}
function InstallClick(){
var version = [Link]("select").value;
switch(version)
{
case "ver1":
let obj1 = new HDFCBank_Version1();
[Link]("<h2>Version-1 Installed</h2>");
[Link]();
break;
case "ver2":
let obj2 = new HDFCBank_Version2();
[Link]("<h2>Version-2 Installed</h2>");
[Link]();
break;
case "ver3":
let obj3 = new HDFCBank_Version3();
[Link]("<h2>Version-3 Installed</h2>");
[Link]();
break;
default:
[Link]("Please Select a Version to Install");
break;
}
}
</script>
</head>
<body>
<fieldset>
<legend>HDF Bank Application</legend>
<select>
<option value="-1">Select Version</option>
<option value="ver1">Version-1 2022</option>
<option value="ver2">Version-2 2023 (May)</option>
<option value="ver3">Version-3 2023 (Aug)</option>
</select>
<button onclick="InstallClick()">Install</button>
</fieldset>
</body>
</html>
Sudhakar Sharma
Sep 2, 2023
Inhertiance Rule: If super class have a constructor then the derived class constructor must call the
super class constuctor.
Syntax:
class Super
{
constructor() { }
}
class Derived extends Super
{
constructor(){
super();
}
}
Polymorphism
- The terms Poly means "Many" and Morphos means "Forms".
- The component ability to function for various situations, is designated as "Polymorphism".
- In technical terms a single base class object can use the memory of multiple derived classes.
Syntax:
var obj = new Array(new Class1(), new Class2(), new Class3());
(or)
var obj = [ ];
obj[0] = new Class1();
obj[1] = new Class2();
Ex:
<script>
class Employee
{
FirstName;
LastName;
Designation;
Print(){
[Link](`${[Link]} ${[Link]} - ${[Link]}<br>`);
}
}
class Developer extends Employee
{
FirstName = "Raj";
LastName = "Kumar";
Designation = "Developer";
Role = "Developer Role : Build, Debug, Test, Deploy";
Print(){
[Link]();
[Link](`${[Link]}`);
}
}
class Admin extends Employee
{
FirstName = "Kiran";
LastName = "Rao";
Designation = "Admin";
Role = "Admin Role : Authorizations & Authentications";
Print(){
[Link]();
[Link](`${[Link]}`);
}
}
class Manager extends Employee
{
FirstName = "Tom";
LastName = "Hanks";
Designation = "Manager";
Role = "Manager Role : Approvals";
Print(){
[Link]();
[Link](`${[Link]}`);
}
}
let employees = new Array(new Developer(), new Admin(), new Manager());
var designation = prompt("Enter Designation");
for(var employee of employees){
if([Link]===designation){
[Link]();
}
}
</script>
window: It provides the properties and methods that are used to control the browser
window.
alert()
confirm()
prompt()
print()
open()
close() etc...
document : It provides all properties and methods that are used to control the
document in window.
write()
getElementById()
appendChild() etc..
location : It provides properties and methods that are used to access client
location details.
Ex:
<script>
[Link](`
Server Name | IP : ${[Link]} <br>
Protocol : ${[Link]} - ${([Link]==="http:")?"You are using Live
Server":"You are using File System"} <br>
Port : ${[Link]} <br>
Url : ${[Link]}
`);
</script>
FAQ: How to navigate to any specific page dynamically ?
Ans: By using "[Link]"
Syntax:
[Link] = "newPath";
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function LoginClick(){
var userid = [Link]("UserId").value;
var password = [Link]("Password").value;
if(userid==="john" && password==="admin"){
[Link] = "../public/[Link]";
} else {
[Link] = "./[Link]";
}
}
</script>
</head>
<body>
<h2>Login</h2>
<dl>
<dt>UserId</dt>
<dd><input type="text" id="UserId"></dd>
<dt>Password</dt>
<dd><input type="password" id="Password"></dd>
</dl>
<button onclick="LoginClick()">Login</button>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intra Links</title>
<script>
function ViewClick(){
var list = [Link]("list");
switch([Link]){
case "#home":
[Link] += "You are viewing Home<br>";
break;
case "#men":
var now = new Date();
[Link] += "Mens Fashion<br>" + [Link]() + "<br>";
break;
case "#women":
var now = new Date();
[Link] += "Women Fashion<br>"+ [Link]() + "<br>";
break;
case "#kids":
var now = new Date();
[Link] += "Kids Fashion<br>"+ [Link]() + "<br>" ;
break;
}
}
</script>
<style>
header {
background-color: darkcyan;
color:white;
padding: 5px;
text-align: center;
}
section {
display: grid;
grid-template-columns: 3fr 9fr;
}
ul {
list-style: none;
margin-left: -40px;
}
li {
width: 150px;
background-color: darkcyan;
color:white;
font-size: 20px;
padding: 3px;
margin-bottom: 20px;
}
main {
height: 400px;
overflow: auto;
}
nav a {
color:white;
text-decoration: none;
}
.btn-back {
width: 200px;
background-color: black;
color:white;
padding: 3px;
text-align: center;
}
.btn-back a {
color:white;
text-decoration: none;
}
.header-nav {
display: flex;
justify-content: center;
}
.header-nav img {
margin-right: 30px;
border:2px solid white;
box-shadow: 2px 2px 2px gray;
}
</style>
</head>
<body>
<header>
<h2>Shopper</h2>
<div class="header-nav">
<div>
<a href="#men"><img src="images/[Link]" width="50" height="50"></a>
</div>
<div>
<a href="#women"> <img src="images/[Link]" width="50" height="50"></a>
</div>
<div>
<a href="#kids"> <img src="images/[Link]" width="50" height="50"></a>
</div>
</div>
</header>
<section>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#men">Men's Fashion</a></li>
<li><a href="#women">Women's Fashion</a></li>
<li><a href="#kids">Kid's Fashion</a></li>
</ul>
<div>
<button onclick="ViewClick()">Recently Viewed</button>
<p id="list"></p>
</div>
</nav>
<main>
<h2 id="home">Home</h2>
<p>We understand that <span><b><a href="#offer">Realme Offers</a></b></span> you may
have questions about the Microsoft Services Agreement. We have an FAQ page
([Link] that provides more
information, including what Microsoft products and services it covers. Whenever we make changes,
we provide a summary of the most notable changes to the current Microsoft Services Agreement.
We will also continue to provide a summary of the changes to the previous version, and a link to the
previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
<p>We understand that you may have questions about the Microsoft Services Agreement. We
have an FAQ page ([Link] that
provides more information, including what Microsoft products and services it covers. Whenever we
make changes, we provide a summary of the most notable changes to the current Microsoft Services
Agreement. We will also continue to provide a summary of the changes to the previous version, and
a link to the previous version, of the Microsoft Services Agreement on the Summary of Changes
([Link] page.</p>
</main>
</section>
</body>
</html>
navigator: It provides the properties and methods that are used to get the
browser details.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
[Link]((position)=>{
[Link](`
Latitude : ${[Link]} <br>
Longitude: ${[Link]}
`);
})
</script>
</head>
<body>
<h2>Please Allow your location </h2>
</body>
</html>
Sudhakar Sharma
Sep 5, 2023
Browser Objects
- Window
- Location
- Navigator
history
- It provides the properties and methods that are used to control the browser history.
- It provides the members
length get the count of pages in current browsing history
back() go to previous page in history
forward() go to next page in history
goto() go to specific page in history
Syntax:
<button onclick="[Link]()">
<button onclick="[Link]('[Link]')">
Ex:
<script>
if([Link]>3){
alert("You have to register for more");
[Link]="../public/[Link]";
} else {
[Link]("You can view max 3 pages for free..");
}
</script>
document
- It provides properties and methods to handle document elements.
getElementById()
querySelector()
appnedChild()
write()
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function bodyload(){
var images = [Link]("img");
for(var i=0; i<[Link]; i++){
[Link](images[i].src);
}
}
</script>
</head>
<body onload="bodyload()">
<p>Welcome</p>
<h2>JavaScript</h2>
<img src="../public/images/[Link]" width="100" height="100">
<img src="../public/images/[Link]" width="100" height="100">
<img src="../public/images/[Link]" width="100" height="100">
</body>
</html>
Startup Code
var checkboxes = ? getElementsByName()
verify which on is checked
return its value
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function Submit(){
[Link]("p").innerHTML = "";
var checkboxes = [Link]("course");
for(var i=0; i<[Link]; i++){
if(checkboxes[i].checked){
[Link]("p").innerHTML += checkboxes[i].value + "<br>";
}
}
}
</script>
</head>
<body>
<div>
<button onclick="Submit()">Submit</button>
</div>
<input type="checkbox" onchange="Submit()" name="course" value="Java"> Java
<input type="checkbox" onchange="Submit()" name="course" value=".NET"> .NET
<input type="checkbox" onchange="Submit()" name="course" value="UI"> UI
<p></p>
</body>
</html>
Problem: Get the count of elements that are using the CSS class called
"form-select"
1. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form align="center" action="[Link]">
<h1>Google</h1>
<input type="text" name="search" size="40">
<p>
<button>Search</button>
</p>
</form>
</body>
</html>
2. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
var data = [
{Topic: "HTML", Details:["Void Elements", "Normal Elements","RC Data Elements"]},
{Topic: "JavaScript", Details:["Variables", "Data Types", "Operators"]}
];
function bodyload(){
var str = [Link]([Link]("=")+1);
[Link]("h2").innerHTML = `${str} Topics`;
var obj = [Link]((item)=>{
return [Link]==str;
});
if(obj) {
[Link](topic=>{
var li = [Link]("li");
[Link] = topic;
[Link]("ol").appendChild(li);
})
} else {
[Link]("Topic not found");
}
}
</script>
</head>
<body onload="bodyload()">
<h2></h2>
<ol>
</ol>
</body>
</html>
State Management
Sudhakar Sharma
Sep 6, 2023
Local Storage
- It is the storage of browser.
- It is permanent storage.
- It is available even after the browser closed or user restarts the device.
- It is accessible across pages and tabs.
- You have to manually delete from memory.
Syntax:
[Link]("key", "value")
[Link]("key");
[Link]("key");
[Link]();
Ex:
1. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<script>
function LoginClick(){
var userid = [Link]("UserId").value;
[Link]("uid", userid);
[Link] = "[Link]";
}
</script>
</head>
<body>
<dl>
<h3>User Login</h3>
<dt>User Id</dt>
<dd><input type="text" id="UserId"></dd>
<dt>Password</dt>
<dd><input type="password" id="Password"></dd>
</dl>
<button onclick="LoginClick()">Login</button>
</body>
</html>
2. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<script>
function bodyload(){
if([Link]("uid")==null){
[Link]="[Link]";
} else {
[Link]("p").innerHTML = `Hello ! ${[Link]("uid")}`;
}
}
function SignoutClick(){
[Link]("uid");
[Link] = "[Link]";
}
</script>
</head>
<body onload="bodyload()">
<h3>Home <button onclick="SignoutClick()">Signout</button> </h3>
<p></p>
</body>
</html>
Session Storage
- It is temporary storage.
- It is not accessible across tabs in browser.
- It is deleted automatically when browser is closed.
Syntax:
[Link]("key", "value");
[Link]("key");
[Link]("key");
[Link]()
Ex:
1. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<script>
function LoginClick(){
var userid = [Link]("UserId").value;
[Link]("uid", userid);
[Link] = "[Link]";
}
</script>
</head>
<body>
<dl>
<h3>User Login</h3>
<dt>User Id</dt>
<dd><input type="text" id="UserId"></dd>
<dt>Password</dt>
<dd><input type="password" id="Password"></dd>
</dl>
<button onclick="LoginClick()">Login</button>
</body>
</html>
2. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<script>
function bodyload(){
if([Link]("uid")==null){
[Link]="[Link]";
} else {
[Link]("p").innerHTML = `Hello ! ${[Link]("uid")}`;
}
}
function SignoutClick(){
[Link]("uid");
[Link] = "[Link]";
}
</script>
</head>
<body onload="bodyload()">
<h3>Home <button onclick="SignoutClick()">Signout</button> </h3>
<p></p>
</body>
</html>
Cookies
- Cookies are simple text documents in browser memory, where you can store the client details and
access across pages or tabs.
- Cookies can be
a) In-Memory [Temporary]
b) Persistent [Permanent]
Syntax:
[Link] = "key=value; expiry=dateTime";
Ex:
1. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<script>
function LoginClick(){
var userid = [Link]("UserId").value;
[Link] = `uid=${userid}`;
[Link] = "[Link]";
}
</script>
</head>
<body>
<dl>
<h3>User Login</h3>
<dt>User Id</dt>
<dd><input type="text" id="UserId"></dd>
<dt>Password</dt>
<dd><input type="password" id="Password"></dd>
</dl>
<button onclick="LoginClick()">Login</button>
</body>
</html>
2. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
<script>
function bodyload(){
var userid = [Link];
[Link]("p").innerHTML = [Link]([Link]("=") + 1);
}
function SignoutClick(){
[Link] = "[Link]";
}
</script>
</head>
<body onload="bodyload()">
<h3>Home <button onclick="SignoutClick()">Signout</button> </h3>
<p></p>
</body>
</html>
Summary
- Query String
- Local Storage
- Session Storage
- Cookies
JavaScript Ajax
JavaScript Ajax
Sudhakar Sharma
•
Sep 7, 2023
Syntax:
open("methodName", "url", async:boolean);
send();
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function GetDataClick(){
var http = new XMLHttpRequest();
[Link]("get","../public/[Link]",true);
[Link]();
[Link] = function(){
if([Link]==4){
var now = new Date();
[Link]("fetchTime").innerHTML = [Link]();
[Link]("container").innerHTML = [Link];
}
}
}
function bodyload(){
var now = new Date();
[Link]("timer").innerHTML = `Page Loaded on : $
{[Link]()}`;
}
</script>
</head>
<body onload="bodyload()">
<p id="timer"></p>
<button onclick="GetDataClick()">Get Data</button>
<p id="fetchTime"></p>
<div id="container">
</div>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function FetchClick(){
var http = new XMLHttpRequest();
[Link]("get", "[Link]
[Link]();
[Link] = function(){
if([Link]==4){
var products = [Link]([Link]);
[Link](product=>{
var li = [Link]("li");
[Link] = [Link];
[Link]("ol").appendChild(li);
})
}
}
}
</script>
</head>
<body>
<button onclick="FetchClick()">Fetch</button>
<ol>
</ol>
</body>
</html>
jQuery
- jQuery is a JavaScript library to build UI.
- A library comprises of pre-defined functions which you have implement and design the dynamic
interface.
- Write Less Do More.
- "John Resig" introduced jQuery library in 2006.
- jQuery can handle DOM manipulations, Interactions, validations, Styles, Animations by using pre-
defined methods.
- It reduces browser compatibility issues.
3. The complete jQuery library is defined in any anonymous function "( )".
(
... jquery functions...
)
4. You have to import the jquery anonymous method and use in page. All jquery methods are
imported by using "$".
<script>
$(()=>{
// jquery scope
})
</script>
(or)
<script>
$(function(){
})
</script>
Sudhakar Sharma
Sep 8, 2023
text() innerText
html() innerHTML
css() define styles dynamically
val() get and set value
attr() get and set attribute
prop() get and set property
prepend() add as prefix
append() add as suffix
appendTo() add to specific element
before() add above
after() add below
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script>
$(()=>{
$("p").html(" <b>Library</b>");
$("p").prepend("jQuery");
$("p").append("-Write less, do More");
$("p").before("Web Development");
$("p").after("Client Side");
})
</script>
</head>
<body>
<p></p>
</body>
</html>
Input
- query string
- prompt()
- form elements
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script>
var categories = ["Electronics", "Footwear", "Fashion"];
$(()=>{
[Link](category=>{
$(`<li>${category}</li>`).appendTo("ol");
$(`<option>${category}</option>`).appendTo("select");
})
})
</script>
</head>
<body>
<ol></ol>
<select></select>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script>
function LoadProducts(){
fetch("[Link]
.then(res=>[Link]())
.then(products=>{
[Link](product=>{
$(`<tr>
<td> ${[Link]} </td>
<td> ${[Link]} </td>
<td> <img src=${[Link]} width="100" height="100"> </td>
<td> ${[Link]} [${[Link]}] </td>
</tr>`).appendTo("tbody");
})
})
}
$(()=>{
LoadProducts();
})
</script>
</head>
<body>
<table width="100%" border="1">
<thead>
<tr>
<th>Title</th>
<th>Price</th>
<th>Preview</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
JavaScript Events:
- Event is a message sent by sender to its subscriber in order notify the change.
- Event uses "Observer" pattern, which is a communication pattern.
- Event follows a "Delegate" mechansim [ function pointer ].
Syntax:
function InsertClick() => Subscriber
{
}
Syntax:
<button onclick="InsertClick()">
Event Listener:
- It allows to configure a trigger for any element dynamically.
- You can define event for element without using Event Handlers.
Syntax:
[Link]("btn").addEventListener("EventName", function(){
});
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function bodyload(){
[Link]("btnInsert").addEventListener("click", ()=>{
[Link]("Record Inserted");
})
}
</script>
</head>
<body onload="bodyload()">
<button id="btnInsert">Insert</button>
</body>
</html>
Event Arguments:
- Every event handler can have 2 default arguments
1. this
2. event
Syntax:
<button onclick="InsertClick(this, event)">
InsertClick(event, this)
InsertClick(event)
InsertClick(this)
InsertClick()
- "this" sends information about current element to the subscriber, which can be
id, name, class, value, src, width, height, href etc..
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function InsertClick(obj){
[Link](`
Button Id : ${[Link]} <br>
Button Name: ${[Link]} <br>
Button Class: ${[Link]} <br>
`);
}
</script>
</head>
<body>
<button id="btnInsert" name="Insert" class="btn btn-primary"
onclick="InsertClick(this)">Insert</button>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function Database(buttonName){
switch(buttonName){
case "Insert":
[Link]("Record Inserted");
break;
case "Delete":
[Link]("Record Deleted");
break;
case "Update":
[Link]("Record Updated");
break;
}
}
</script>
</head>
<body>
<button name="Insert" onclick="Database([Link])">Insert</button>
<button name="Update" onclick="Database([Link])">Update</button>
<button name="Delete" onclick="Database([Link])">Delete</button>
</body>
</html>
- "event" sends information about current event to the subscriber, which includes
clientX, clientY, which, shiftKey, ctrlKey, altKey, keyCode, charCode etc..
<button onclick="InsertClick(event)">
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function GetPosition(e){
if(([Link]>=159 && [Link]<=212) && ([Link]>=181 && [Link]<=184)){
[Link]("p").innerHTML= "Belt Cost : ₹ 300/-";
} else {
[Link]("p").innerHTML = "You clicked on image";
}
if([Link]){
[Link]("../public/images/[Link]","Kids","width=300 height=400");
}
}
</script>
</head>
<body>
<img onclick="GetPosition(event)" src="../public/images/[Link]" width="300"
height="400">
<p></p>
</body>
</html>
Sudhakar Sharma
Sep 9, 2023
Events in JavaScript
- Event
- Event Handler
- Observer
- Delegate
- Subscriber
- Sender
- Event Args
a) Default Event Args
- this
- event
Custom Args:
- Every event can be configured with custom args.
- A custom argument can be any type
a) Primitive Type
b) Non Primitive Type
Syntax:
<button onclick="InsertClick(0, ' ', true, [ ], { }, [ { }, { }])">
function InsertClick(...params) { }
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function InsertClick(...product){
var [id, name, stock, cities, rating] = product;
[Link](`
Product Id : ${id} <br>
Name : ${name}<br>
Stock: ${stock} <br>
Cities: ${[Link]()} <br>
Rating: ${[Link]}
`);
}
</script>
</head>
<body>
<button onclick="InsertClick(1, 'TV', true, ['Delhi','Hyd'],{Rate:4.5})" >Click</button>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function InsertClick(obj, e, cities, rating){
[Link](`
Button Id : ${[Link]} <br>
X Position : ${[Link]} <br>
Cities: ${[Link]()} <br>
Rating: ${[Link]}
`);
}
</script>
</head>
<body>
<button id="btnInsert" onclick="InsertClick(this, event, ['Delhi','Hyd'],{Rate:4.5})" >Click</button>
</body>
</html>
- The event listener in JavaScript or jQuery can have only one default parameter, which can collect
both element and event details.
- Event listener can't have "this" as default. It can have only "event".
- "event" can access both object and event details
[Link]
[Link]
[Link]
[Link]
Syntax:
[Link]("button").addEventListener("click", (e)=>{
[Link];
[Link]
})
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function bodyload(){
[Link]("btnInsert").addEventListener("click",(event)=>{
[Link](`
Button Id : ${[Link]} <br>
X Position: ${[Link]}
`);
});
}
</script>
</head>
<body onload="bodyload()">
<button id="btnInsert">Insert</button>
</body>
</html>
jQuery Event:
- jQuery can use only event listener.
- jQuery will not use event handler
Syntax:
<button> Insert </button>
$("button").click(event=>{
[Link];
[Link];
})
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script>
function LoadProducts(){
fetch("[Link]
.then(res=>[Link]())
.then(products=>{
[Link](product=>{
$(`<tr>
<td> ${[Link]} </td>
<td> ${[Link]} </td>
<td> <img src=${[Link]} width="100" height="100"> </td>
<td> ${[Link]} [${[Link]}] </td>
</tr>`).appendTo("tbody");
})
})
}
$(()=>{
$("button").click((e)=>{
LoadProducts();
[Link](`
Button Id : ${[Link]} \n
Button Name: ${[Link]} \n
X Position: ${[Link]}
`);
})
})
</script>
</head>
<body>
<button id="btnLoad" name="Load">Load Data</button>
<table width="100%" border="1">
<thead>
<tr>
<th>Title</th>
<th>Price</th>
<th>Preview</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
fieldset {
display: grid;
grid-template-columns: 6fr 6fr;
}
</style>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script>
$(()=>{
$("#btnSubmit").click(()=>{
$("#lblName").html($("#txtName").val());
$("#lblAge").html($("#txtAge").val());
$("#lblCity").html($("#lstCities").val());
})
$("#lstCities").change(()=>{
if($("#lstCities").val()=="-1"){
$("#lblCity").html("City Not Available").css("color","red");
} else {
$("#lblCity").html($("#lstCities").val()).css("color","black");
}
})
})
</script>
</head>
<body>
<fieldset>
<legend>User Details</legend>
<div>
<dl>
<dt>Name</dt>
<dd><input type="text" id="txtName"></dd>
<dt>Age</dt>
<dd><input type="number" id="txtAge"></dd>
<dt>City</dt>
<dd>
<select id="lstCities">
<option value="-1">Select City</option>
<option>Delhi</option>
<option>Hyd</option>
</select>
</dd>
</dl>
<button id="btnSubmit">Submit</button>
</div>
<div>
<table border="1" width="100%">
<tr>
<td width="100">Name</td>
<td id="lblName"></td>
</tr>
<tr>
<td>Age</td>
<td id="lblAge"></td>
</tr>
<tr>
<td>City</td>
<td id="lblCity"></td>
</tr>
</table>
</div>
</fieldset>
</body>
</html>
Browser Events
1. Mouse Events
2. Keyboard Events
3. Button Events
4. Form Events
5. Clipboard Events
6. Element State Events
7. Touch Events
8. Timer Events etc...
Sudhakar Sharma
1. Mouse Events
Handler Name Listener Name
-----------------------------------------------
onmouseover mouseover
onmouseout mouseout
onmousedown mousedown
onmouseup mouseup
onmousemove mousemove
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function GetDetails(str){
[Link]("p").innerHTML = str;
}
function ChangeImage(){
[Link]("fashion").src = "../public/images/[Link]";
}
function ResetImage(){
[Link]("fashion").src = "../public/images/[Link]";
}
</script>
</head>
<body>
<div>
<img id="fashion" onmousedown="ChangeImage()" onmouseup="ResetImage()"
src="../public/images/[Link]" width="200" height="300">
</div>
<marquee scrollamount="15" onmouseover="[Link]()" onmouseout="[Link]()">
<img onmouseover="GetDetails('30% OFF On Smart Watches')" src="../public/images/[Link]"
width="200" height="200">
<img onmouseover="GetDetails('AC at low cost EMI - SBI Bank Offers')"
src="../public/images/[Link]" width="200" height="200">
<img onmouseover="GetDetails('Refridgirator 40% OFF on Electronics')"
src="../public/images/[Link]" width="200" height="200">
</marquee>
<p align="center"></p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function SetPosition(e){
var flag = [Link]("flag");
[Link] = "fixed";
[Link] = [Link] + "px";
[Link] = [Link] + "px";
[Link]("status").innerHTML = `Mouse X Position : ${[Link]} px <br>
Mouse Y Position : ${[Link]} px`;
}
</script>
</head>
<body onmousemove="SetPosition(event)">
<div style="height: 1000px;">
move mouse pointer to test.
<div id="status"></div>
</div>
<img src="../public/images/[Link]" width="50" height="50" id="flag">
</body>
</html>
Task:
2. Keyboard Events
onkeyup keyup
onkeydown keydown
onkeypress keypress
Ex:
data/[Link]
[
{
"UserName":"john"
},
{
"UserName":"john12"
},
{
"UserName":"john_nit"
},
{
"UserName":"david"
}
]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function VerifyUser(){
var username = [Link]("UserName").value;
var userError = [Link]("userError");
fetch("../data/[Link]")
.then(res=>[Link]())
.then(users=>{
for(var user of users){
if([Link]===username){
[Link] = "User Name Taken - Try another".fontcolor('red');
break;
} else {
[Link] = "User Name Available".fontcolor('green');
}
}
})
}
function VerifyPassword(e){
var pwdError = [Link]("pwdError");
if([Link]>=65 && [Link]<=90){
[Link] = "block";
} else {
[Link] = "none";
}
}
</script>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
</head>
<body>
<dl>
<dt>User Name</dt>
<dd>
<input type="text" id="UserName" onkeyup="VerifyUser()">
</dd>
<dd id="userError"></dd>
<dt>Password</dt>
<dd>
<input type="password" id="Password" onkeypress="VerifyPassword(event)">
</dd>
<dd id="pwdError" style="color:goldenrod; display: none;">
<span class="bi bi-exclamation-triangle-fill"></span> Warning : Caps ON
</dd>
</dl>
</body>
</html>
3. Button Events
onclick click
ondblclick dblclick
oncontextmenu contextmenu [right click]
onselectstart selectstart [selecting content on page using drag]
FAQ: How to disable right click in page and selection of content in page?
Ans: By configuring oncontextmenu & onselectstart events in document.
You have to configure them with "return false".
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function OpenImage(){
[Link]('../public/images/[Link]','Women','width=300 height=400');
}
[Link] = function(){
alert('Right Click Disabled');
return false;
}
</script>
</head>
<body>
<img ondblclick="OpenImage()" src="../public/images/[Link]" width="100" height="100">
<p>double click to view large</p>
<h1>Right Click is Disabled</h1>
</body>
</html>
onchange change
onblur blur
onfocus focus
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function ShowMsg(){
[Link]("msg").innerHTML = "Name in Block Letters".fontcolor('red');
}
function ChangeCase(){
var username = [Link]("UserName").value;
[Link]("UserName").value = [Link]();
[Link]("msg").innerHTML = "";
}
</script>
</head>
<body>
<dl>
<dt>User Name</dt>
<dd><input type="text" id="UserName" onfocus="ShowMsg()" onblur="ChangeCase()"></dd>
<dd id="msg"></dd>
</dl>
</body>
</html>
1. Mouse Events
2. Keyboard Events
3. Button Events
4. Element State Events
Clipboard Events
oncut cut
oncopy copy
onpaste paste
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function Cut(){
[Link]("p").innerHTML = "Removed and Copied to Clipboard";
}
function Copy(){
[Link]("p").innerHTML = "Copied to Clipboard";
}
function Paste(){
[Link]("p").innerHTML = "Inserted Clipboard";
}
</script>
</head>
<body>
<textarea oncut="Cut()" oncopy="Copy()" onpaste="Paste()" rows="4" cols="40"></textarea>
<p></p>
</body>
</html>
Timer Events
setTimeout()
clearTimeout()
setInterval()
clearInterval()
Form Events
onsubmit submit
onreset reset
Syntax:
<form onsubmit="action()" onreset="action()">
</form>
FAQ's:
1. How to disable the default functionality configured for submit and reset buttons?
A. By using the event argument "preventDefault()".
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function SubmitClick(e){
[Link]();
alert("Form Will submit its data to server");
}
</script>
</head>
<body>
<form onsubmit="SubmitClick(event)" onreset="alert('Form will reset')">
<dl>
<dt>User Name</dt>
<dd><input type="text" name="UserName"></dd>
</dl>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</form>
</body>
</html>
2. How to submit form data to server on the events triggered by other elements in form?
A. You can submit form by using "submit()" method for <form> element dynamically.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function CityChange(){
[Link]();
}
</script>
</head>
<body>
<form name="frmRegister">
<dl>
<dt>User Name</dt>
<dd><input type="text" name="UserName"></dd>
<dt>Select City</dt>
<dd>
<select onchange="CityChange()" name="City">
<option>Select Your City</option>
<option>Delhi</option>
<option>Hyd</option>
</select>
</dd>
</dl>
</form>
</body>
</html>
3. How to disable the event configured for parent element after triggering the child event?
A. By using the event argument "stopPropagation()"
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function DivClicked(e){
alert("Div Clicked");
}
function ButtonClicked(e){
alert("Button Clicked");
[Link]();
}
</script>
<style>
div {
padding: 50px;
border:2px solid black;
width: 400px;
}
</style>
</head>
<body>
<div onclick="DivClicked()">
<p>Container have click Event</p>
<button onclick="ButtonClicked(event)">Click Me</button>
</div>
</body>
</html>
Touch Events
ontouchstart touchstart
ontouchend touchend
ontouchmove touchmove
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function GetDetails(str){
switch(str){
case "watch":
[Link]("h2").innerHTML="50% OFF on Smart Watches";
break;
case "ac":
[Link]("h2").innerHTML = "Winter Sales - Special offers on A/C's";
break;
}
}
</script>
</head>
<body>
<img ontouchstart="GetDetails('watch')" src="../public/images/[Link]" width="200"
height="200">
<img ontouchstart="GetDetails('ac')" src="../public/images/[Link]" width="200" height="200">
<h2></h2>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function MoveImage(e){
var img = [Link]("img");
[Link] = "fixed";
[Link] = [Link][0].clientY + "px";
[Link] = [Link][0].clientX + "px";
}
</script>
</head>
<body>
<img ontouchstart="MoveImage(event)" src="../public/images/[Link]" width="100"
height="100">
</body>
</html>
jQuery Effects
- jQuery provides various methods for pre-defined CSS effects.
slide()
slideToggle()
fade()
fadeToggle()
show()
hide()
toggle() etc..
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script>
$(()=>{
$("button").click(()=>{
$("img").fadeToggle(2000);
})
})
</script>
</head>
<body>
<button>Show / Hide</button>
<br><br>
<div>
<img src="../public/images/[Link]" width="200" height="200">
</div>
</body>
</html>
jQuery UI
- It is a component library for jQuery similar to bootstrap.
- It provides various jQuery effects, interactions and widgets.
- You can build effective UI faster.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/jquery-ui/[Link]">
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/jquery-ui/[Link]"></script>
<script>
$(()=>{
$("img").draggable();
})
</script>
</head>
<body>
</body>
</html>
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/jquery-ui/[Link]">
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/jquery-ui/[Link]"></script>
<script>
$(()=>{
$("#topics").accordion();
})
</script>
</head>
<body>
<div id="topics">
<h2>HTML</h2>
<div>
<p>It is a markup language.</p>
</div>
<h2>CSS</h2>
<div>
<p>It is for styles in HTML</p>
</div>
</div>
</body>
</html>
jQuery Ajax
jQuery Ajax
Sudhakar Sharma
jQuery Ajax
Syntax:
$.ajax({settingsObject})
{
method : It defines the request method.
GET - Fetching
POST - Submitting
PUT - Update
PATCH - Partial Update
DELETE- Deleting
Syntax:
$.ajax( {
method : "get",
url : "path",
success : (response)=> { },
error : (jqError)=> { }
}
);
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Ajax</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script>
$(()=>{
var now = new Date();
$("p").html(`Page Loaded on ${[Link]()}`)
$("button").click(()=>{
$.ajax({
method: "get",
url: "../data/[Link]",
success: (response)=>{
$("#data").html(response);
},
error: (errorObj)=> {
$("#data").html(`${[Link]} : Page you requested ${[Link]}`);
}
})
})
})
.ajaxStart(()=>{
alert(`Your request for help document started..`);
})
.ajaxSuccess(()=>{
alert(`Your request being processed successfully..`);
})
.ajaxComplete(()=>{
alert(`Your request processed`);
})
.ajaxStop(()=>{
alert(`Response is ready to load in your page`);
})
</script>
</head>
<body>
<p></p>
<button>Load Help</button>
<div>
<pre id="data">
</pre>
</div>
</body>
</html>
Note: You can't configure event handler for any element, which is dynamically generated in page. To
to define events for dynamically generated element, you have to use jquery document "on()".
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopper</title>
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/[Link]">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<script src="../node_modules/jquery/dist/[Link]"></script>
<script>
function LoadCategories(){
$.ajax({
method: 'get',
url: '[Link]
success: (categories)=> {
[Link]("all");
[Link](category=>{
$(`<option
value=${category}>${[Link]()}</option>`).appendTo("#lstCategories");
})
}
})
}
function LoadProducts(url){
$("main").html("");
$.ajax({
method: 'get',
url: url,
success: (products=>{
[Link](product=>{
$(`
<div class="card p-2 m-2" style="width:200px">
<img src=${[Link]} class="card-img-top" height="130">
<div class="card-header overflow-auto" style="height:130px">
${[Link]}
</div>
<div class="card-body">
Price : ${[Link]} <br>
Rating: ${[Link]}
</div>
<div class="card-footer">
<button id="btnAdd" value=${[Link]} class="btn btn-danger w-100"> <span
class="bi bi-cart3"></span> Add to Cart</button>
</div>
</div>
`).appendTo("main");
})
})
})
}
$(()=>{
LoadCategories();
LoadProducts('[Link]
$("#lstCategories").change(()=>{
if($("#lstCategories").val()=="all") {
LoadProducts('[Link]
} else {
LoadProducts(`[Link]
("#lstCategories").val()}`);
}
})
$(document).on("click","#btnAdd",(e)=>{
alert(`Add Clicked ${[Link]}`);
})
})
</script>
</head>
<body class="container-fluid">
<header class="p-2 text-center bg-dark text-white">
<span class="h3"> <span class="bi bi-cart4"></span> Shopper</span>
</header>
<section class="row mt-2">
<nav class="col-2">
<label class="form-label fw-bold">Select Category</label>
<select class="form-select" id="lstCategories">
</select>
</nav>
<main class="d-flex flex-wrap col-10 overflow-auto" style="height: 500px;">
</main>
</section>
</body>
</html>
jQuery Plugin's
[Link]
jQuery Plugins
Sudhakar Sharma
jQuery Plugin's
- A plugin is just like an extention for web application.
- There are various 3rd party plugins for JavaScript and jQuery, which are used to build application
more faster.
- You can search for plugin in "[Link]"
Ex: Barcode
2. Link the jquery library for barcode into page and assign 12 digit code with
".EAN13( ' 12 digit code ')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/[Link]">
<title>Document</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/jquery-ean13/dist/[Link]"></script>
<script>
$(()=>{
$("#barcode").EAN13('900999341111');
})
</script>
</head>
<body class="container-fluid">
<div class="card m-2 p-2 w-25">
<img class="card-img-top" src="../public/images/[Link]" height="300">
<div class="card-footer">
<canvas width="220" height="60" id="barcode">
Your browser doesn't support canvas.
</canvas>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../node_modules/jsgrid/dist/[Link]">
<link rel="stylesheet" href="../node_modules/jsgrid/dist/[Link]">
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/jsgrid/dist/[Link]"></script>
<script>
$(()=>{
$("#grid").jsGrid({
width: "100%",
height: "400px",
filtering: true,
editing: true,
sorting: true,
paging: true,
data: [
{Name: "Samsung TV", Price:45000.33, Stock: true},
{Name: "Mobile", Price: 20000.33, Stock: false},
{Name: "Watch", Price: 4000.32, Stock: true}
],
fields: [
{ name: "Name", type: "text", width: 150 },
{ name: "Price", type: "number", width: 50 },
{ name: "Stock", type: "checkbox", title: "In Stock", sorting: false },
{ type: "control" }
]
});
})
</script>
</head>
<body>
<h2>Products Grid</h2>
<div id="grid">
</div>
</body>
</html>
1. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/[Link]/[Link]"></script>
<script>
$(()=>{
$("#btnLogin").click(()=>{
$.cookie('userName', $("#UserName").val(), { expires: 2 });
[Link] = "[Link]";
})
})
</script>
</head>
<body>
<h2>Login</h2>
User Name : <input type="text" id="UserName"> <button id="btnLogin">Login</button>
</body>
</html>
2. [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../node_modules/jquery/dist/[Link]"></script>
<script src="../node_modules/[Link]/[Link]"></script>
<script>
$(()=>{
if($.cookie("userName")==undefined) {
[Link]="[Link]";
} else {
$("div").html(`Hello ! ${$.cookie("userName")}`);
}
$("#btnSignout").click(()=>{
$.removeCookie("userName");
[Link] = "[Link]";
})
})
</script>
</head>
<body>
<h2>Success <button id="btnSignout">Signout</button> </h2>
<div></div>
</body>
</html>
Sass
Sass
Sudhakar Sharma
Sass
- Syntactically Awesome Style Sheet
- It css pre-processor or pre-compiler.
- Sass provides several programming features, which a developer can use and implement to design
complex styles in simplified manner.
- Browser can't understand sass code directly, it is trans-compiled into CSS.
Developer => Write => Sass Code => Transcompiles => CSS => Browser
C:\>
2. Write code in sass syntax [all css styles & attributes are same]
Ex:
1. Add a new folder by name "scss" into "src" folder.
2. Add a new file by name
"[Link]"
.container{
border:1px solid darkmagenta;
padding: 20px;
background-color: rgb(236, 167, 236);
box-shadow: 5px 4px 2px black;
h2 {
color:darkmagenta;
font-family: Arial;
}
p{
font-family: Georgia;
font-size: 24px;
color:maroon;
}
}
Sass Variables
- You can store values in variable and configure to any elements.
- You can re-use the values.
- Sass variables are declared by using "$"
$variableName : value;
- You can access and use variable at any location using "$variableName"
Ex:
[Link]
.container{
border:$border;
padding: 20px;
background-color: $bgColor ;
box-shadow: $shadow ;
h2 {
color: $color;
font-family: Arial;
}
p{
font-family: Georgia;
font-size: 24px;
color:maroon;
}
}
fieldset {
border: $border;
box-shadow: $shadow;
background-color: $bgColor;
margin-top: 20px;
padding: 5px;
font-family: $font;
color:$color;
legend {
border:$border;
background-color: white;
}
}
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../src/scss/[Link]">
</head>
<body>
<div class="container">
<h2>Sass</h2>
<p>Syntactically Awesome Style Sheet</p>
</div>
<fieldset>
<legend>Features of Sass</legend>
<p>CSS Pre Compiler for effective UI</p>
<p>Faster Designs</p>
<p>Logical Functions</p>
</fieldset>
</body>
</html>
Sass Functions
- Sass function are used to control the flow of execution.
@If
@for
Syntax:
@for $variableRef from initial through final
{
Ex:
[Link]
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../src/scss/[Link]">
</head>
<body>
<div class="box-1">
<img src="../public/images/[Link]" width="100" height="100">
</div>
<div class="box-2">
<img src="../public/images/[Link]" width="100" height="100">
</div>
<div class="box-3">
<img src="../public/images/[Link]" width="100" height="100">
</div>
<div class="box-4">
<img src="../public/images/[Link]" width="100" height="100">
</div>
</body>
</html>
Sass Mixins
- It is like a reusable function
Syntax:
@mixin Name(params)
{
}
@include Name(values);
Ex:
[Link]
$theme : red;
@if $theme==green {
@include SetTheme(darkgreen, green , lightgreen);
} @else if $theme==red {
@include SetTheme(darkred, red , #ffcccc );
} @else {
@include SetTheme(black, gray , lightgray );
}
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../src/scss/[Link]">
</head>
<body>
<div class="container">
<h2>Sass</h2>
<p>Syntactically Awesome Style Sheet</p>
</div>
</body>
</html>
Sudhakar Sharma
Sass
- Variables
- Functions
@if
@for
- Mixins
Sass Module System
- A module comprises of set of variables, functions and mixins.
- You can import into any file and reduce the number of requests.
- It will reduce the load time and allows reusability.
- Every "scss" file is considered as a module.
- If you are designing as module then its name must start with "_fileName.scss".
- You can import any file into another by using "@import".
Ex:
1. Add following files
_variables.scss
_mixins.scss
@import "variables";
@mixin SetTheme()
{
.container{
border: $border;
box-shadow: $boxShadow;
padding: 20px;
h2 {
text-shadow: $txtShadow;
}
}
}
@import "mixins";
@include SetTheme();
3. Transcompile [Link]
4. Link to [Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="../src/scss/[Link]">
</head>
<body>
<div class="container">
<h2>Sass</h2>
<p>Syntactically Awesome Style Sheet</p>
</div>
</body>
</html>
MongoDB
(Database)
- Database is used to handle relational data.
- Database are classified into
a) SQL
b) Non-SQL
- SQL is Structured Query Language, it is a language used for managing data.
- Non-SQL database don't use any SQL language.
- MongoDB is non-sql data or no-sql.
- It comprises of simple JavaScript like methods for manipulation.
- It maintains data in JSON format.
- It is structure less [Schema less]
- Data Replications
- Ad-hoc Queries [Dynamic Queries]
- MongoDB is document based.
Setup MongoDB
1. Download and Install MongoDB Community Server
[Link]
3. Select "Start"
mongodb://[Link]:27017
(or)
mongodb://localhost:27017
MongoDB Commands:
Sudhakar Sharma
Video Library
[Demo Project]
Abstract: A video library that allows creators to upload videos and general users can
watch videos. It is aim is to keep all related videos in various categories so
that browsing can be easy and can tack the activity of user with history.
Proposed System: Creator can upload various types of videos without any
restrictions. How ever admin can validate the videos before
making them available for general users.
Hardware Requirements:
4GB RAM
500 GB HDD
Software Requirements
OS :Windows-8+ version
Front End : HTML, CSS, Bootstrap, JS, jQ
Back End : Node JS, Express JS, MongoDB
Modules:
1. Admin
2. Creator
3. User
4. Videos Browse & Filter
5. Payment
Admin Roles
- Can Add creator
- Can Remove creator or modify creator details
- Can Add User
- Can Remove or Modify user details
- Can Add Video
- Can Remove or modify Videos
Creator Roles
- Register / Login
- Add Video
- Modify and Remove Video
User Roles
- Register
- Login
- Watch Videos
- Like , dislike or comment on videos.
Data Models
1. Conceptual Model
2. Physical Model
3. Logical Model
4. Entity Model
MongoDB Commands
Sudhakar Sharma
MongoDB Terminology
3. Document : It is a JSON object that contains data stored with key & value
reference.
MongoDB Commands
>show dbs
>use databaseName
>[Link]("name", {attributes})
>[Link]("name")
Syntax:
> [Link]("name", { autoIndexId:true, max:10, capped:true, size:1048576 })
> [Link]("tblcreator",{autoIndexId:true, max:10, capped:true, size:1048576})
>show collections
> [Link]()
> [Link]()
6. To Remove any database, first switch into database and run the command
>[Link]()
insertOne()
insertMany()
Ex:
> [Link]({adminId:1, Name:'John', Password:'john123', Email:'john@[Link]',
Age:22, Mobile:'+919876543210'})
Sudhakar Sharma
Syntax:
[Link]({query})
Ex:
> [Link]({ })
> [Link]({ id:7 })
> [Link]({ category: "jewelery" })
> [Link]({ price:{$gt:600} })
> [Link]({ stock:true })
Ex: AND
Ex: OR
Updating Documents
----------------------------
- You can change the field names, and values by using the update methods.
a) updateOne()
b) updateMany()
Syntax:
>[Link]({findQuery}, {updateQuery})
>[Link]({id:7},{$set:{price:500}})
>[Link]({category:"electronics"}, {$set:{stock:false}})
>[Link]({}, {$rename: { "oldName" : "newName" }})
>[Link]("newName")
Remove Documents
- To remove any document from a collection mongoDB provides the methods
a) deleteOne()
b) deleteMany()
Syntax:
>[Link]({findQuery})
> [Link]({$and:[{category:"electronics"},{price:{$gt:600}}] })
> [Link]({id:5})
> [Link]({category:"electronics"})
Summary:
CRUD
- createCollection()
- insertOne()
- insertMany()
- find()
- updateOne()
- updateMany()
- deleteOne()
- deleteMany()
Node JS
- It is a JavaScript based server side scripting technology built on google chrome V8 compiler.
- It uses JavaScript server side.
- It is modular.
- It is light weight.
- It is faster.
- It is Asynchronous.
- It is single threaded.
Sudhakar Sharma
4. Node JS uses "Require JS" module system, hence library is imported by using
"require()" method.
ES Module:
import { className } from "moduleName";
Node
var refName = require("moduleName");
[Link]
[Link]()
(or)
5. Node JS programs use JavaScript only as language not for DOM. Hence you should not use DOM
methods in Node JS.
- Variables
- Data Types
- Operators
- Statements
- Functions
- OOP
- Console Methods
Node REPL
- REPL refers to
R - Read
E - Execute
P - Print
L - Loop
- Node provides a terminal where you can test all Node functions and objects.
C:\> node
>node [Link]
Members:
arch
availableParallelism
cpus
endianness
freemem
getPriority
homedir
hostname
loadavg
networkInterfaces
platform
release
setPriority
tmpdir
totalmem
type
userInfo
uptime
version
machine
constants
EOL
devNull
Syntax:
var os = require("os");
[Link]([Link]());
[Link]([Link]());
Ex:
var os = require("os");
2. Path
- It provides properties and methods that are used to get information about a file on server.
Members:
resolve
normalize
isAbsolute
join
relative
toNamespacedPath
dirname
basename
extname
format
parse
sep
delimiter
win32
posix
_makeLong
Syntax:
var path = require("path");
[Link]([Link]("D:\\online-store\\images\\[Link]"));
Ex:
var path = require("path");
var inputFile = "D:\\oline-store\\public\\images\\[Link]";
var extention = [Link](inputFile);
if(extention==".png" || extention==".jpg"){
[Link]("File Uploaded Successfully..");
} else {
[Link](`You can upload only JPG and PNG files\nYou Current file is of type ${extention}`);
}
3. FS [File Stream]
- It provides a set of properties and methods that are used to read and write data into file.
- Node JS provides 2 types of methods
a) Async Methods
b) Sync Methods
var fs = require("fs");
Ex: Async
var fs = require("fs");
MongoDB Drivers
Sudhakar Sharma
2. You can connect with MongoDB server by using "connect()" method. It requires a
connectionstring.
[Link]("mongodb://[Link]:27017")
.then((clientObject)=> { onsuccess })
.catch((error)=> { on error })
Syntax:
var mongoClient = require("mongodb").MongoClient;
[Link]("mongodb://localhost:27017")
.then((clientObject)=>{
[Link]("Connected Successfully..");
})
.catch((error)=>{
[Link](error);
})
3. You can communicate with any database in MongoDB by using "Client Object".
[Link]("databaseName");
[Link]("collectionName").find()
.insertOne()
.insertMany()
.updateOne()
.deleteOne() etc..
Syntax:
[Link]("tblproducts").find({}).toArray().then((docs)=>{
[Link](docs);
}).catch((error)=>{
[Link](error);
})
[Link]
-----------
[Link]("mongodb://[Link]:27017").then((clientObj)=>{
[Link]("tblproducts").find({id:4}).toArray().then((documents)=>{
[Link](documents);
}).catch((error)=>{
[Link](error);
})
}).catch((error)=>{
[Link](error);
})
[Link]
-----------
var mongoClient = require("mongodb").MongoClient;
[Link](conStr).then((clientObj)=>{
var database = [Link]("videosdb");
var data = {
"Admin_Id": 2,
"Name": "David",
"Password": "david@11",
"Email": "david@[Link]",
"Age": 32,
"Phone": "+919988776331"
}
[Link]("adminTable").insertOne(data).then(()=>{
[Link]("Record Inserted");
}).catch((error)=>{
[Link](error);
})
})
[Link]
----------
[Link](conStr).then((clientObj)=>{
var database = [Link]("videosdb");
[Link]("adminTable").updateOne({Admin_Id:1},{$set:{Age:29}}).then(()=>{
[Link](`Record Updated..`);
})
})
[Link]
----------
var mongoClient = require("mongodb").MongoClient;
[Link](conStr).then((clientObj)=>{
var database = [Link]("videosdb");
[Link]("adminTable").deleteOne({Admin_Id:2}).then(()=>{
[Link](`Record Deleted..`);
})
})
Express JS
Sudhakar Sharma
- Distributed computing allows two different applications running on two different machines to share
information.
- It also allows 2 different applications running in 2 different process of same machine to share
information.
RMI J2EE
[Remote Method Invocation]
EJB Java
[Enterprise Java Beans]
Remoting .NET
a) SOAP
b) REST
c) JSON
- The aim of API is to make data available to all devices and platforms.
- API allows data to reach any place, any time and to any device.
- To create the business logic and server side API you need a server side technology and middleware,
which is Node and Express.
Express JS
----------------
- It is a middleware framework.
- Middleware is a software used in network based applications to handle communication between
devices and apps.
- A framework is a software architectural pattern that can build application and control the
application flow.
- It is a set of libraries.
- Install Express JS in your project
Ex:
[Link]
[Link]("/",(request, response)=>{
[Link]("Welcome to API");
});
[Link](6600);
[Link]("Server Started : [Link]
REST API
Sudhakar Sharma
•
Sep 29, 2023
Note: A body-parser library is required in old versions of server apps, to convert the
client data into JSON.
How ever the latest express js library is in-built provided with a body-parser.
Syntax:
var express = require("express");
var app = express();
})
- Request object provides a set of properties and methods that are used by server to request data
from client.
Query String
Form Body
Cookies
LocalStorage
SessionStorage etc..
- Response object is used by server to send a response to client, which can be
HTML Response
Text Response
XML Response
JSON Response
File Response etc..
Syntax:
[Link](4400);
[Link]
--------------
var express = require("express");
[Link](4400);
[Link](`Server Started : [Link]
Route Parameters:
-------------------------
- A route parameter allows user to query any content directly from URL.
- To accept the query values from client your route must accept parameters.
- The route parameters are defined by using "/:paramName"
Syntax:
[Link]("/products/:id/:name/:price", (req, res)=>{
})
/products/1/tv/34000
[Link]
[Link]
[Link]
Ex:
[Link]
[Link]("/products/:id/:name/:price",(req, res)=>{
[Link](`
<h2>Product Details</h2>
<dl>
<dt>Product Id </dt>
<dd>${[Link]}</dd>
<dt>Name</dt>
<dd>${[Link]}</dd>
<dt>Price</dt>
<dd>${[Link]}</dd>
</dl>
`);
})
[Link](4400);
[Link](`Server Started : [Link]
[Link]
[Link](4400);
[Link](`Server Started : [Link]
Sudhakar Sharma
Note: You can download and install web debugger for API testing.
- Fiddler
- Postman
- Swagger etc..
REST API post, put and delete requires additional configuration in server side
application.
a) Setup CORS
b) Use CORS
c) Configure URL Encoding
d) Convert data to JSON
Syntax:
> npm install cors --save
[Link](cors);
[Link]([Link]({extended:true});
[Link]([Link]());
Ex:
[Link]
[Link]([Link]({
extended:true
}));
[Link]([Link]());
[Link]("/",(req, res)=>{
[Link]("Home");
});
[Link]("/deleteuser", (req,res)=>{
[Link]("Delete User Details..");
[Link]();
})
[Link](4400);
[Link](`Server Started : [Link]
Project Example:
Deployment
Sudhakar Sharma
Oct 4, 2023
Cloud Deployment
- You can use local servers for deploying web application
- IIS [Internet Information Services Manager]
- Apache Tomcat
- WAMP server
6. Open IIS from program and create a new website, which is a "Virtual Directory".
[Link]
Firebase
GIT Hub Pages
AWS
AZURE
Netify etc..
Firebase Deploying
2. Visit firebase official website and login with your google account
[Link]
3. Go to "Console" category
- Add Project
name : ui-developer-portfolio
5. Create a project on your PC, make sure that all files are kept in public folder.
6. Make sure that you are using only CDN links for libraries
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UI-Developer</title>
<link href="[Link]
rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/
Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link rel="stylesheet" href="[Link]
[Link]">
<script src="[Link]
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL
" crossorigin="anonymous"></script>
</head>
<body class="container-fluid">
<header class="bg-warning text-dark d-flex justify-content-between p-2">
<div class="h4">Rakesh</div>
<div>
I am Talented Web Developer
</div>
<div>
<span class="bi bi-facebook me-2"></span>
<span class="bi bi-twitter me-2"></span>
<span class="bi bi-instagram"></span>
</div>
</header>
<section style="height: 100vh;" class="bg-dark mt-4 text-white">
</section>
</body>
</html>
8. Open Terminal
>firebase login
>firebase init
>firebase deploy
Sudhakar Sharma
Oct 6, 2023
Name : student-portfolio
Share : public
Create Repository
4. Go to "Settings" of repository
5. Click on "Pages" and configure your page after connecting with Editor.
[Link]
youraccount/student-portfolio
[Link]
C:\Users\HP\OneDrive\Documents\GitHub\student-portfolio
12. It will identify the changes in your project, which you have to commit by adding summary
15. Settings => Pages => Branch "main" => folder "root" => Save
[Link]