? Chapter 1 - Introduction To HTML
? Chapter 1 - Introduction To HTML
🔹
🔹
✅
CHAPTER 1: INTRODUCTION TO
HTML
Key Points
● HTML uses tags to structure content
● Used to create:
○ Headings
○ Paragraphs
○ Lists
● Developed to share scientific information between researchers
● Now used for designing and formatting web pages
⸻
Example
<html>
<head>
<title>My Page</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>
Common Questions
● What is HTML?
● Define Hypertext
● Why is HTML called a markup language?
Quick Revision
● HTML = Hypertext Markup Language
● Used to create web pages
● Uses tags to structure content
2000–2008: XHTML
● Stricter version of HTML
● Required:
○ Proper nesting
○ Closing tags
● Not widely used
⸻
2008–2014: HTML5
● Developed by WHATWG
● Major features:
○ Semantic tags:
◆ <header>, <footer>, <section>, <nav>
○ Multimedia:
◆ <audio>, <video>
○ APIs:
◆ Geolocation
◆ Offline storage
● Officially released in 2014 (W3C)
⸻
2014–Present: Living Standard
● No fixed versions
● Continuously updated
● New features:
○ <dialog>, <template>
○ Web components
⸻
Important Points for Exam
● Father of HTML → Tim Berners-Lee
● HTML developed at → CERN
● HTML5 released in → 2014
● HTML is now a living standard
⸻
Common Questions
● Who developed HTML?
● Explain the evolution of HTML
● What are features of HTML5?
⸻
Quick Revision
● 1989 → Idea (TBL)
● 1995 → HTML 2.0
● 1997 → HTML 3.2 / 4.0
● 2000 → XHTML
● 2014 → HTML5
⸻
Definition (Write Exactly)
● The primary objective of HTML is to structure and present
content on the World Wide Web in a way that is
understandable to both web browsers and users.
● HTML is designed to serve as the foundational language for
creating web pages and web applications.
1. Content Structuring
● HTML provides a framework for organizing and structuring
content into meaningful elements.
Examples:
● Headings → <h1> to <h6>
● Paragraphs → <p>
● Lists → <ul>, <ol>, <li>
● Tables → <table>, <tr>, <td>
3. Presentation of Content
● HTML defines how content is displayed (with help of CSS)
Examples:
● Text formatting → <strong>, <em>, <small>
● Media → <img>, <video>, <audio>
4. Semantic Structure
● HTML provides semantic elements to define meaning of content
Examples:
● <header>, <footer>, <article>, <section>
Importance:
● Improves SEO (Search Engine Optimization)
● Helps screen readers and accessibility tools
7. Cross-Platform Compatibility
● HTML is platform-independent
● Works on:
○ Computers
○ Mobile phones
○ Tablets
● Requires only a web browser
9. Standards Compliance
● HTML follows standards set by:
○ W3C
○ WHATWG
● Ensures:
○ Consistency
○ Compatibility across browsers
Basic Structure
<html>
<head>
<title>Document Title</title>
</head>
<body>
Document body content
</body>
</html>
⸻
Explanation of Tags
1.
<html>
Tag
● This tag encloses the complete HTML document
● It contains:
○ <head> section
○ <body> section
● </html> indicates the end of HTML document
2.
<head>
Tag
● Represents the document header
● Contains:
○ <title>
○ Meta information
● Closing tag → </head>
3.
<title>
Tag
● Used to define the title of the document
● Appears on the browser tab
● Must be inside <head>
● Closing tag → </title>
4.
<body>
Tag
● Represents the main content of the document
● Contains:
○ Text
○ Links
○ Tables
○ Forms
● Closing tag → </body>
⸻
Example Program (Important for Exam)
<html>
<head>
<title>This is document title</title>
</head>
<body>
This is an HTML Document.
</body>
</html>
Output
● This is an HTML Document.
Common Questions
● Explain the basic structure of HTML
● Write an HTML program showing structure
● Difference between <head> and <body>
Quick Revision
● HTML structure = <html> + <head> + <body>
● <title> inside <head>
● Content shown inside <body>
Key Points
● Used to define titles and subtitles
● Browser automatically adds:
○ One line before and after headings
Example Program
<html>
<head>
<title>Heading Example</title>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
Output
● This is heading 1
● This is heading 2
● This is heading 3
● This is heading 4
● This is heading 5
● This is heading 6
Quick Revision
● 6 heading tags
● <h1> biggest, <h6> smallest
● Used for titles
⸻
⸻
Attributes in HTML
Definition (Write Exactly)
● An attribute is used to define the characteristics of an HTML
element and is placed inside the opening tag.
● Attributes consist of two parts:
○ Name (property)
○ Value (assigned value in quotes)
Align Attribute
● Used to set alignment of paragraph text
Values:
● "left"
● "center"
● "right"
Example Program
<html>
<head>
<title>Paragraph Align Attribute Example</title>
</head>
<body>
<p align="left">This is left aligned</p>
<p align="center">This is center aligned</p>
<p align="right">This is right aligned</p>
</body>
</html>
Output
● This is left aligned
● This is center aligned
● This is right aligned
Common Questions
● What is <p> tag?
● Define attribute with example
● Explain align attribute
Quick Revision
● <p> → paragraph
● Attribute = name + value
● Align → left / center / right
⸻
Key Points
● Contains user-visible content
● Essential for webpage display
● Only one <body> per document
Quick Revision
● <body> → main content
● Visible elements only
Key Points
● Centers:
○ Text
○ Images
○ Other elements
Example Program
<html>
<head>
<title>Centering Content Example</title>
</head>
<body>
<p>This text is not in the center.</p>
<center>
<p>This text is in the center.</p>
</center>
</body>
</html>
Output
● This text is not in the center.
● This text is in the center.
Common Questions
● What is <body> tag?
● Explain <center> tag with example
⸻
Quick Revision
● <body> → visible content
● <center> → aligns content to center
⸻
Key Points
● Used to break lines without starting a new paragraph
● No closing tag → <br> only
● Called an empty element
⸻
Example Program
<html>
<head>
<title>Line Break Example</title>
</head>
<body>
<p>
Hello<br>
How are you?<br>
Bye<br>
Tom
</p>
</body>
</html>
Output
Hello
How are you?
Bye
Tom
⸻
Common Questions
● What is <br> tag?
● Why is <br> called an empty tag?
Quick Revision
● <br> → next line
● Empty tag
● No closing tag
Key Points
● Draws a line from left to right margin
● Used for section separation
● No closing tag → <hr>
Example Program
<html>
<head>
<title>Horizontal Line Example</title>
</head>
<body>
<p>This is paragraph one and should be on top</p>
<hr>
<p>This is paragraph two and should be at bottom</p>
</body>
</html>
Output
This is paragraph one and should be on top
This is paragraph two and should be at bottom
Common Questions
● What is <hr> tag?
● Difference between <br> and <hr>
⸻
Quick Revision
● <hr> → horizontal line
● Empty tag
● Used for separation
⸻
⸻
Example Program
<html>
<head>
<title>Bold Text Example</title>
</head>
<body>
<p>Apples are <b>red</b></p>
</body>
</html>
Output
Apples are red
⸻
Quick Point
● <b> → makes text bold
Example Program
<html>
<head>
<title>Italic Text Example</title>
</head>
<body>
<p>Apples are <i>red</i></p>
</body>
</html>
⸻
Output
Apples are red
Quick Point
● <i> → italic text
Example Program
<html>
<head>
<title>Underlined Text Example</title>
</head>
<body>
<p>Apples are <u>red</u></p>
</body>
</html>
Output
Apples are red
Quick Point
● <u> → underline text
Example Program
<html>
<head>
<title>Superscript Text Example</title>
</head>
<body>
<p>This is <sup>superscript</sup> text</p>
</body>
</html>
Output
This is superscript text (shown above line)
Quick Point
● <sup> → text goes up
⸻
Important Points for Exam
● All formatting tags are container tags
● Used to change appearance only
● Very common in short questions
Common Questions
● What are formatting tags?
● Explain <b>, <i>, <u> with examples
● What is superscript text?
Quick Revision
● <b> → bold
● <i> → italic
● <u> → underline
● <sup> → above text
Key Points
● Font size remains the same
● Position is below the normal text
● Commonly used in:
○ Chemical formulas (e.g., H₂O)
Example Program
<html>
<head>
<title>Subscript Text Example</title>
</head>
<body>
<p>The following word uses a <sub>subscript</sub> typeface.</p>
</body>
</html>
⸻
Output
The following word uses a subscript typeface.
Quick Point
● <sub> → text goes down
Quick Revision
● <sub> → below text
● Same size, lower position
⸻
Attributes of
<font>
Tag
1. Size
● Changes the text size
2. Color
● Changes the text color
3. Face
● Changes the font style (e.g., Courier New)
⸻
Key Points
● Text remains changed until </font> tag is closed
● Can change:
○ One attribute OR
○ All attributes together
Example Program
<html>
<head>
<title>Setting Font Size, Face and Color</title>
</head>
<body>
<font size="2" color="red" face="Courier New">
This is Font demo.
</font>
</body>
</html>
⸻
Output
This is Font demo. (in red color, smaller size, Courier New style)
Common Questions
● What is <sub> tag?
● What are attributes of <font> tag?
● Why is <font> tag not used in modern HTML?
Quick Revision
● <sub> → below text
● <font> → size, color, face
● Deprecated → use CSS
⸻
Output
● Background → Red
● Text → Blue
● Output: This is color demo.
Background Image
Definition (Write Exactly)
● The background attribute is used to set an image as the
background of a webpage.
Output
● Background → Image ([Link])
● Text: Welcome to HTML Programming
⸻
Common Questions
● What is bgcolor attribute?
● How to set background image in HTML?
● What is default background color of webpage?
Quick Revision
● Default → white
● bgcolor → background color
● text → text color
● background → image
⸻
6. Explain background tags in HTML.
Answer
● Background tags are used to set background color or image of
a webpage.
● bgcolor attribute sets background color
● text attribute sets text color
● background attribute sets background image
⸻
2. Discuss the objectives of HTML.
Answer
● To structure web content using elements
● To create hyperlinks for navigation
● To support multimedia (images, audio, video)
● To provide semantic structure
● To enable user interaction using forms
● To ensure cross-platform compatibility
● To integrate with CSS and JavaScript
⸻
<html>
<head>
<title>All Tags Example</title>
</head>
<hr>
<hr>
<hr>
<hr>
<hr>
<hr>
</body>
</html>
📘
🔹
✅
Tag Purpose
<table> Creates table
<tr> Defines table row
<td> Defines table data
(cell)
<th> Defines table
heading
⸻
Key Points
● <td> → normal cell (left aligned)
● <th> → heading cell (bold + centered)
● Table is divided into:
○ Rows
○ Columns
Important Attributes
1. Cellpadding
● Defines space between cell border and content
2. Cellspacing
● Defines space between table cells
Attributes
1. bgcolor
● Sets background color
2. bordercolor
● Sets border color
3. colspan
● Merges columns
4. rowspan
● Merges rows
Example Program
<html>
<head>
<title>HTML Table Width/Height</title>
</head>
<body>
<table border="1" width="400" height="150">
<tr>
<td>Apple</td>
<td>Oranges</td>
</tr>
<tr>
<td>Grapes</td>
<td>Pear</td>
</tr>
</table>
</body>
</html>
Common Questions
● What are table tags in HTML?
● Difference between <td> and <th>
● What is cellpadding and cellspacing?
● Explain rowspan and colspan
Quick Revision
● <table> → table
● <tr> → row
<html>
<head>
<title>Complete Table Example</title>
</head>
<body>
<table border="2"
bordercolor="blue"
bgcolor="lightgreen"
cellpadding="10"
cellspacing="5"
width="500"
height="200">
<tr>
<td>Science</td>
<td>85</td>
</tr>
</table>
</body>
</html>
● <td> → data
● <th> → heading
● rowspan / colspan → merging
2.2 Form
Purpose of Forms
● Used in:
○ Registration forms
○ Login forms
○ Feedback forms
● Collects data like:
○ Name
○ Email
○ Password
Attributes of
<form>
Tag
1. action
● Specifies where the data is sent
● Usually a server file (PHP, ASP, etc.)
⸻
2. method
● Specifies how data is sent
Types:
● GET
○ Data sent in URL
○ Less secure
● POST
○ Data sent securely
○ Used for sensitive data
3. target (Optional)
● Specifies where to display response
● Example:
○ _self → same page
○ _blank → new tab
Form Elements
Forms can contain different input controls:
● Text fields
● Textarea
● Radio buttons
● Checkboxes
● Buttons
● Dropdown lists
⸻
Example Program
<html>
<head>
<title>Form Example</title>
</head>
<body>
<form action="[Link]" method="POST">
Name: <input type="text"><br><br>
Email: <input type="text"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
⸻
Common Questions
● What is HTML form?
● Explain <form> tag with syntax
● Difference between GET and POST
Quick Revision
● Form → collects data
● action → destination
● method → GET / POST
Example Program
<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form>
First name: <input type="text" name="first_name"><br>
Last name: <input type="text" name="last_name">
</form>
</body>
</html>
Attributes of
<input>
(Text)
● type → Specifies input type (text)
● name → Name of control (sent to server)
● value → Default value
● size → Width of text box
● maxlength → Maximum characters allowed
2. Password Input
Definition (Write Exactly)
● Password input control is a single-line text input that masks the
characters entered by the user.
Example Program
<html>
<head>
<title>Password Input Control</title>
</head>
<body>
<form>
User ID: <input type="text" name="user_id"><br>
Password: <input type="password" name="password">
</form>
</body>
</html>
Important Point
● Uses: type="password"
● Characters appear as dots or stars
⸻
Example Program
<html>
<head>
<title>Multiple-Line Input Control</title>
</head>
<body>
<form>
Description:<br>
<textarea name="description" rows="5" cols="50">
Enter description here...
</textarea>
</form>
</body>
</html>
Attributes of
<textarea>
● name → Name of control
● rows → Number of rows
● cols → Number of columns
Quick Revision
● Text → one line
● Password → hidden
● Textarea → many lines
2.2.2 Checkboxes
Key Point
● Created using <input> tag
● type="checkbox" is used
Example Program
<html>
<head>
<title>Checkbox Control</title>
</head>
<body>
<form>
<input type="checkbox" name="India" value="on"> India<br>
<input type="checkbox" name="China" value="on"> China
</form>
</body>
</html>
Attributes of Checkbox
● type → Specifies input type (checkbox)
● name → Name of the checkbox (sent to server)
● value → Value sent when checkbox is selected
● checked → Used to select checkbox by default
Quick Revision
● Checkbox → multiple options
● type="checkbox"
● checked → default selection
⸻
Common Mistake (Important)
● Don’t confuse with Radio Button
○ Checkbox → multiple selection
○ Radio → single selection
Key Point
● Created using <input> tag
● type="radio" is used
● All options must have the same name
⸻
Example Program
<html>
<head>
<title>Radio Box Control</title>
</head>
<body>
<form>
<input type="radio" name="subject" value="Male"> Male<br>
<input type="radio" name="subject" value="Female"> Female
</form>
</body>
</html>
Quick Revision
● Radio → one option only
● Same name → group
● checked → default
Key Point
● Created using <select> tag
● Options are added using <option> tag
Example Program
<html>
<head>
<title>Select Box Control</title>
</head>
<body>
<form>
<select name="dropdown">
<option value="Male" selected>Male</option>
<option value="Female">Female</option>
</select>
</form>
</body>
</html>
Attributes of
<select>
Tag
● name → Name of control sent to server
● size → Number of visible options
● multiple → Allows selecting multiple options
Attributes of
<option>
Tag
● value → Value sent to server
● selected → Default selected option
● label → Alternative label for option
Quick Revision
● Select box → dropdown
● <select> + <option>
● multiple → many selections
Important Tip
● By default → only one option selected
● Use multiple → for many selections
⸻
Great—this is the last part of Forms (very important)
2.2.5 Buttons
Key Point
● Created using <input> tag
● Defined using type attribute
Types of Buttons
⸻
1. Submit Button
● Used to submit form data to the server
<input type="submit" value="Submit">
2. Reset Button
● Used to clear all form fields
<input type="reset" value="Reset">
3. Button
● Used to perform custom actions (JavaScript)
<input type="button" value="OK">
4. Image Button
● Used to create a button using an image
<input type="image" src="[Link]">
⸻
Example Program
<html>
<head>
<title>Button Demo</title>
</head>
<body>
<form>
<input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset">
<input type="button" value="OK" name="ok">
</form>
</body>
</html>
⸻
Quick Revision
● Submit → send data
● Reset → clear form
● Button → custom action
● Image → button with image
2.3 Images
Image Tag
● Images are inserted using <img> tag
● It is an empty tag (no closing tag)
⸻
Syntax
<img src="Image URL" attributes>
Important Points
● <img> tag has no closing tag
● It only contains attributes
● Image path must be correct (same folder or full path)
Important Attributes
● src → Specifies image path
● width → Width of image
● height → Height of image
Example Program
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<img src="[Link]" width="400" height="600">
</body>
</html>
Output Explanation
● Image [Link] will be displayed on webpage
● File must be in the same folder
Quick Revision
● <img> → image tag
● src → path
● No closing tag
Excellent—this is a very important theory + definition question
2.4 Iframe
Purpose of Iframe
● Display:
○ Videos
○ Maps
○ External websites
● Used to show content from another source
⸻
Syntax
<iframe src="URL" width="value" height="value" title="description"></
iframe>
Attributes of
<iframe>
● src → URL of the page to embed
● width → Width of iframe
● height → Height of iframe
● title → Description (important for accessibility)
Example Program
<html>
<head>
<title>Iframe Example</title>
</head>
<body>
<h1>Embedding an External Page</h1>
<iframe src="[Link] width="600" height="400"
title="Java Tutorial"></iframe>
</body>
</html>
⸻
Output Explanation
● Displays external website inside webpage
● Example: javatpoint site appears inside frame
Quick Revision
● Iframe → embed page
● src → link
● Used for videos, maps
2.5 Fieldset
Key Point
● Groups form controls together
● Improves structure and clarity
Legend Tag
Definition
● <legend> is used to give a title (caption) to the grouped fields
⸻
Syntax
<fieldset>
<legend>Group Title</legend>
<!-- Form fields go here -->
</fieldset>
Example Program
<html>
<head>
<title>Fieldset Example</title>
</head>
<body>
<form>
<fieldset>
<legend>Personal Information</legend>
Name: <input type="text"><br><br>
Email: <input type="text">
</fieldset>
</form>
</body>
</html>
⸻
Important Points for Exam
● <fieldset> → groups related fields
● <legend> → gives title
● Used inside forms
Quick Revision
● Fieldset → group
● Legend → title
⸻
Definition (Write Exactly)
A hyperlink is used to navigate from one webpage to another webpage
or to a specific part of a page.
Key Point
● Created using <a> tag
● Called anchor tag
● Link can be:
○ Text
○ Image
Syntax
<a href="URL">Link Text</a>
Important Attribute
● href (Hypertext Reference) → Specifies the destination URL
⸻
Example Program
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<p>Click following link</p>
<a href="[Link]
</body>
</html>
Output Explanation
● “Google” appears as a clickable link
● Clicking it opens Google homepage
Quick Revision
● Anchor → link
● <a> tag
● href → URL
Very Important
● Anchor tag has both opening and closing tag
● Anything inside becomes clickable
2.7 Frames
⸻
Key Terms
● Frameset → Collection of frames
● <frameset> → Defines layout
● <frame> → Loads webpage inside frame
Important Points
● <frameset> is used instead of <body>
● rows → horizontal division
● cols → vertical division
Syntax
<frameset cols="20%, 80%">
<frame src="[Link]">
<frame src="[Link]">
</frameset>
Example Program
<html>
<head>
<title>Frames Example</title>
</head>
</frameset>
</html>
Quick Revision
● Frames → divide screen
● <frameset> → layout
● <frame> → content
⸻
10. Explain
<iframe>
tag
● Used to embed another webpage
● Uses src, width, height
3. Fieldset Tag
● <fieldset> → groups fields
● <legend> → title
● Improves readability
⸻
✅
🔹
📘
Perfect—now we start Chapter 5: JavaScript
This chapter is VERY IMPORTANT (theory + small programs)
Key Points
History
Features of JavaScript
Uses of JavaScript
● Form validation
● Event handling (button click, etc.)
● Dynamic content creation
● Interactive web pages
Advantages of JavaScript
2. Immediate Feedback
● No need to reload page
● Faster response
3. Increased Interactivity
4. Rich Interfaces
Limitations of JavaScript
Quick Revision
● Define JavaScript
● Write advantages of JavaScript
● Write limitations of JavaScript
● Explain features of JavaScript
Excellent—this is a VERY IMPORTANT THEORY + PROGRAM question
⸻
Script Tag
● JavaScript code is written inside:
<script>
JavaScript code
</script>
Placement of
<script>
Tag
● Can be placed:
○ Inside <head>
○ Inside <body>
Recommended: inside <head>
Attributes of
<script>
Tag
● language → Specifies scripting language (javascript)
● type → Specifies MIME type (text/javascript)
⸻
Example Program
<html>
<body>
<script language="javascript" type="text/javascript">
[Link]("Hello World!");
</script>
</body>
</html>
Output
● Displays: Hello World!
Important Points
● [Link]() → prints output on webpage
● JavaScript is case-sensitive
● Statements usually end with semicolon (;)
● Spaces, tabs, new lines are ignored
⸻
Quick Revision
● <script> → JavaScript code
● [Link]() → output
● Case-sensitive language
Types of Comments
1. Single-Line Comment
// This is a comment
● Starts with //
● Ends at line
2. Multi-Line Comment
/* This is
multi-line comment */
● Starts with /*
● Ends with */
⸻
Quick Revision
● // → single line
● /* */ → multi-line
1. Script in
<head>
Section
Explanation
● Used when script is executed on events (like button click)
● Functions are usually defined here
Example Program
<html>
<head>
<script type="text/javascript">
function sayHello() {
alert("Hello World");
}
</script>
</head>
<body>
<input type="button" onclick="sayHello()" value="Say Hello">
</body>
</html>
⸻
Output
● Clicking button shows alert box: Hello World
2. Script in
<body>
Section
Explanation
● Used when script runs when page loads
● Directly displays content
Example Program
<html>
<head></head>
<body>
<script type="text/javascript">
[Link]("Hello World");
</script>
<p>This is web page body</p>
</body>
</html>
Output
● Displays:
○ Hello World
○ This is web page body
Quick Revision
● Head → functions/events
● Body → direct execution
● External → separate file
Methods of Output
● [Link]()
● alert()
● Input box
● [Link]()
5.2.1 Alert
Key Point
● Contains only one button (OK)
⸻
Example Program
<html>
<head>
<script type="text/javascript">
function warn() {
alert("This is a warning message!");
}
</script>
</head>
<body>
<p>Click the button to see the result:</p>
<form>
<input type="button" value="Click Me" onclick="warn()">
</form>
</body>
</html>
Output
● Shows alert box → “This is a warning message!”
⸻
Quick Revision
● Alert → message box
● Only OK button
Key Function
● [Link]() → gets value from input field
⸻
Example Program
<html>
<head>
<script>
function getOutput() {
var input = [Link]("inputBox").value;
[Link]("You have entered " + input);
}
</script>
</head>
<body>
<form>
<input type="text" id="inputBox" placeholder="Enter something here">
<button type="button" onclick="getOutput()">Submit</button>
</form>
</body>
</html>
Output
● Displays: You have entered (input value)
Quick Revision
● Input → user data
● getElementById() → get value
5.2.3 Console
Key Function
● [Link]() → prints output in browser console
Example Program
<html>
<body>
<h3>Open the Console to see output</h3>
<script>
[Link]("Hello World!");
</body>
</html>
Output
● Output shown in browser console (F12)
Important Points
● Used for debugging
● Not visible on webpage
● Open using F12 / Developer Tools
⸻
Quick Revision
● Console → debugging
● [Link]()
Key Points
● Avoids repetition of code
● Makes program modular
● Improves readability
Syntax
<script type="text/javascript">
function functionName(parameters) {
// statements
}
</script>
Example
<script type="text/javascript">
function helloWorld() {
alert("Hello World");
}
</script>
Quick Revision
● function keyword used
● Can have parameters or not
Example Program
<html>
<head>
<script type="text/javascript">
function helloWorld() {
[Link]("Hello World!");
}
</script>
</head>
<body>
<p>Click the button to call the function</p>
<form>
<input type="button" value="Hello" onclick="helloWorld()">
</form>
</body>
</html>
⸻
Output
● Clicking button → Hello World!
Important Point
● onclick is used to call function
Quick Revision
● Call function using → functionName()
● Often used with events
5.3.3 Events
⸻
Definition (Write Exactly)
Events are actions that occur in the browser or by the user, which
trigger JavaScript code.
Examples of Events
● Mouse click
● Key press
● Page load
● Window resize
Common Events
● onclick → when button is clicked
● onload → when page loads
● onkeypress → when key is pressed
Example
<button onclick="alert('Button Clicked!')">Click Me</button>
⸻
Output
● Clicking button → shows alert
Important Points
● Events connect HTML + JavaScript
● Used for user interaction
● Part of DOM (Document Object Model)
[Link]
onclick
Event
Example Program
<html>
<head>
<script type="text/javascript">
function sayHello() {
alert("Hello World");
}
</script>
</head>
<body>
<p>Click the button to see result</p>
<form>
<input type="button" onclick="sayHello()" value="Say Hello">
</form>
</body>
</html>
Output
● Click button → Hello World
Quick Revision
● Click → action performed
[Link]
onkeydown
Event
Event
Example Program
<html>
<head>
<script type="text/javascript">
function sayDown() {
alert("Key pressed down");
}
</script>
</head>
<body>
<p>Type in the textbox</p>
<form>
<input type="text" onkeydown="sayDown()">
</form>
</body>
</html>
Output
● Press any key → Key pressed down
Quick Revision
● Key press → event triggered
[Link]
onchange
Event
Example Program
<html>
<head>
<script type="text/javascript">
function sayChange() {
alert("Content changed");
}
</script>
</head>
<body>
<form>
Name:
<input type="text" onchange="sayChange()">
</form>
</body>
</html>
Output
● Change text → Content changed
⸻
Quick Revision
● Value change → event
[Link]
onload
Event
Example Program
<html>
<head>
<script type="text/javascript">
function sayLoad() {
alert("Finished loading the page");
}
</script>
</head>
<body onload="sayLoad()">
</body>
</html>
Output
● Page loads → alert shown
Quick Revision
● Page load → event
[Link]
onmouseover
&
onmouseout
Example Program
<html>
<body>
<script>
function mouseOver() {
[Link]("demo")×style×color = "red";
}
function mouseOut() {
[Link]("demo")×style×color = "black";
}
</script>
</body>
</html>
Output
● Mouse over → text turns red
● Mouse out → text turns black
Quick Revision
● Mouse over → color change
● Mouse out → revert back
Example Program
<html>
<head>
<title>All Events Example</title>
<script type="text/javascript">
function sayHello() {
alert("Hello World (onclick event)");
}
function sayDown() {
alert("Key pressed (onkeydown event)");
}
function sayChange() {
alert("Content changed (onchange event)");
}
function sayLoad() {
alert("Page Loaded (onload event)");
}
function mouseOver() {
[Link]("demo")×style×color = "red";
}
function mouseOut() {
[Link]("demo")×style×color = "black";
}
</script>
</head>
<body onload="sayLoad()">
<br><br>
<br><br>
</body>
</html>
Output Behavior
● Page load → “Page Loaded” alert
● Click button → “Hello World” alert
● Press key → keydown alert
● Change text → change alert
● Mouse over text → color turns red
● Mouse out → color turns black
⸻
Exam Tip (VERY IMPORTANT)
If asked:
“Write a program using different events”
Write this full program
Or write any 3–4 events (if short answer)
Quick Revision
● onclick → button
● onkeydown → typing
● onchange → edit
● onload → page start
● onmouseover/out → hover
⸻ Great—this is the last slightly tricky topic, but I’ll make it super
easy
Program
<html>
<head>
<script type="text/javascript">
function add() {
var num1 = parseInt([Link]("firstNumber").value);
var num2 =
parseInt([Link]("secondNumber").value);
[Link]("result")×value = result;
}
</script>
</head>
<body>
<form>
1st Number:
<input type="text" id="firstNumber"><br><br>
2nd Number:
<input type="text" id="secondNumber"><br><br>
Result:
<input type="text" id="result"><br><br>
</body>
</html>
⸻
Output
● Enter numbers → click Sum → result displayed
Important Functions
● [Link]() → access element
● .value → get/set value
● parseInt() → convert text to number
⸻
Final One-Line Answer
DOM Traversing is the process of accessing HTML elements using
JavaScript to manipulate data dynamically.
Declaration of Variables
Before using a variable, we must declare it using var keyword.
⸻
Syntax
<script type="text/javascript">
var variableName;
</script>
Example
<script type="text/javascript">
var money;
var name;
</script>
Multiple Variables
We can declare multiple variables in one line:
<script type="text/javascript">
var money, name;
</script>
Variable Initialization
⸻
Example
<script type="text/javascript">
var name = "Adam"; // initialization at declaration
var money;
money = 2000; // initialization later
</script>
⸻
What is Untyped Language?
JavaScript does not require data type declaration
Example:
<script>
var x = 10; // number
x = "Hello"; // now string
</script>
Same variable can store different data types
One-Line Answer
A variable is a named container used to store data values in
JavaScript.
Key Points
● Stores multiple values
● Elements are accessed using index (position)
● Index starts from 0
Creating an Array
⸻
Syntax
<script>
var arrayName = new Array("value1", "value2", "value3");
</script>
Example
<script>
var flowers = new Array("Rose", "Lotus", "Jasmine");
</script>
Accessing Elements
<script>
var flowers = ["Rose", "Lotus", "Jasmine"];
[Link](flowers[0]); // Rose
</script>
Important Property
● length → number of elements
<script>
var arr = [10, 20, 30, 40, 50];
[Link]([Link]); // 5
</script>
1.
pop()
● Removes last element
[Link]();
2.
push()
● Adds element at end
[Link]("Grapes");
⸻
3.
shift()
● Removes first element
4.
unshift()
● Adds element at beginning
5.
splice()
● Add/remove elements
[Link](2, 0, "Strawberry"); // insert
[Link](0, 2); // delete
6.
concat()
● Combines arrays
newArray = [Link](arr2);
7.
slice()
● Extracts part of array
res = [Link](0, 2);
<html>
<body>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var dryfruits = ["Pista", "Dates", "Almonds"];
[Link](fruits + "<br>");
[Link]();
[Link](fruits + "<br>");
[Link]("Grapes");
[Link](fruits + "<br>");
[Link]();
[Link](fruits + "<br>");
[Link]("Pear");
[Link](fruits + "<br>");
[Link](2, 0, "Strawberry");
[Link](fruits + "<br>");
[Link](0, 2);
[Link](fruits + "<br>");
</body>
</html>
⸻
Quick Revision (EXAM GOLD)
● Array → collection of values
● Index → starts from 0
● length → size
● push/pop → end
● shift/unshift → beginning
● splice → add/remove
● concat → merge
● slice → extract
One-Line Answer
An array is a collection of elements stored in a single variable and
accessed using index values.
⸻
Definition (Write Exactly)
JavaScript provides the Date object to handle and manipulate date and
time values.
Method Description
getFullYear() Returns year
getMonth() Returns month (0–
11)
getDate() Returns day of
month
getDay() Returns day of
week (0–6)
getHours() Returns hours
getMinutes() Returns minutes
getSeconds() Returns seconds
getMilliseconds() Returns
milliseconds
Example Program
<html>
<head>
<title>Date Functions</title>
</head>
<body>
<script>
var now = new Date();
</body>
</html>
Output Example
● Year: 2025
● Month: 0 (January)
● Date: 18
● Day: 6 (Saturday)
● Time values displayed
⸻
Important Points
● Month starts from 0 (January)
● Day starts from 0 (Sunday)
● Used for time-based operations
One-Line Answer
The Date object in JavaScript is used to create and manipulate date
and time values.
⸻
5.8 String Handling in JavaScript
Creating a String
Syntax
<script>
var str = new String("Hello");
</script>
String Property
● length → returns number of characters
⸻
Example
<script>
var str = new String("This is an apple");
[Link]([Link]);
</script>
Output
● Length = 16
1.
charAt()
● Returns character at given index
[Link](0);
⸻
2.
concat()
● Joins two strings
3.
indexOf()
● Returns position of character
4.
replace()
● Replaces text
5.
substring()
● Extracts part of string
⸻
6.
toLowerCase()
● Converts to lowercase
7.
toUpperCase()
● Converts to uppercase
8.
toString()
● Converts value to string
9.
valueOf()
● Returns primitive value
⸻
Example Program
<html>
<head>
<title>String Methods</title>
</head>
<body>
<script>
var str = "This is string";
var num = 200;
One-Line Answer
A string is a sequence of characters used to store text data in
JavaScript.
⸻
Perfect—this is your exam gold section (5.9 + 5.10 answers)
I’ll give you ready-to-write answers
⸻
5.9 Short Answer Questions
Syntax of JavaScript
JavaScript code is written inside <script> tag.
<script>
[Link]("Hello World");
</script>
Comments in JavaScript
● Single line → // comment
● Multi-line → /* comment */
Placement of JavaScript
● Inside <head>
● Inside <body>
● External file (.js)
⸻
Alert in JavaScript
Alert is used to display a message box.
alert("Hello");
[Link]() Function
Used to display output in browser console.
[Link]("Hello World");
Declare Variables
Using var keyword:
var x = 10;
Constructors in Arrays
Array can be created using constructor:
var arr = new Array(10, 20, 30);
splice() Method
Used to add/remove elements:
var arr = ["A", "B", "C"];
[Link](1, 0, "X"); // insert
onclick Event
Triggered when element is clicked.
<button onclick="alert('Clicked')">Click</button>
onload Event
Triggered when page loads.
<body onload="alert('Loaded')">
<button onclick="hello()">×lick</button>
× ⃣ Various Events
● onclick → click
● onload×→ page load
● onkeydown → key press
● onmouseover → mouse over
Date Functions
var now = new Date();
[Link]();
[Link]();
⸻
Output Systems
● alert() → message
● [Link]() → webpage
● [Link]() → console
FINAL TIP
For exam:
● Learn definitions + 1 example each
● Practice functions, events, arrays