vnd
vnd
Components of WWW
The Components of WWW mainly falls into two categories:
1.Structural Components
2.Semantic Components
Introduction of World Wide Web
Architecture of WWW
The WWW is mainly a distributed client/server service where a client using the browser can access the service using a
server. The Service that is provided is distributed over many different locations commonly known as sites/websites.
•Each website holds one or more documents that are generally referred to as web pages.
•Where each web page contains a link to other pages on the same site or at other sites.
•These pages can be retrieved and viewed by using browsers.
Client/Browser
The Client/Web browser is basically a program that is used to communicate with the webserver on the Internet.
Each browser mainly comprises of three components and these are:
•Controller
•Interpreter
•Client Protocols
•The Controller mainly receives the input from the input device, after that it uses the client programs in order to
access the documents.
•After accessing the document, the controller makes use of an interpreter in order to display the document on the
screen.
•An interpreter can be Java, HTML, javascript mainly depending upon the type of the document.
•The Client protocol can be FTP, HTTP, TELNET
Introduction of World Wide Web
Server
The Computer that is mainly available for the network resources and in order to provide services to the other
computer upon request is generally known as the server.
•The Web pages are mainly stored on the server.
•Whenever the request of the client arrives then the corresponding document is sent to the client.
•The connection between the client and the server is TCP.
•It can become more efficient through multithreading or multiprocessing. Because in this case, the server can
answer more than one request at a time.
URL
URL is an abbreviation of the Uniform resource locator.
•It is basically a standard used for specifying any kind of information on the Internet.
•In order to access any page the client generally needs an address.
•To facilitate the access of the documents throughout the world HTTP generally makes use of Locators.
Introduction of World Wide Web
HTML
Features of WWW
HTML is an abbreviation of Hypertext Markup
Given below are some of the features provided by the World
Language.
Wide Web:
•It is generally used for creating web pages.
•Provides a system for Hypertext information
•It is mainly used to define the contents,
•Open standards and Open source
structure, and organization of the web page.
•Distributed.
XML
•Mainly makes the use of Web Browser in order to provide a
XML is an abbreviation of Extensible Markup
single interface for many services.
Language. It mainly helps in order to define the
•Dynamic
common syntax in the semantic web.
•Interactive
Advantages of WWW
•Cross-Platform
Given below are the benefits offered by WWW:
Disadvantages of WWW
• It mainly provides all the information for
There are some drawbacks of the WWW and these are as
Free.
follows;
• Provides rapid Interactive way of
•It is difficult to prioritize and filter some information.
Communication.
•There is no guarantee of finding what one person is looking for.
• It is accessible from anywhere.
•There occurs some danger in case of overload of Information.
• It has become the Global source of media.
•There is no quality control over the available data.
• It mainly facilitates the exchange of a huge
•There is no regulation.
volume of data.
Introduction of World Wide Web
HTML
HTML is an abbreviation of Hypertext Markup Features of WWW
Language. Given below are some of the features provided by the World
•It is generally used for creating web pages. Wide Web:
•It is mainly used to define the contents, •Provides a system for Hypertext information
structure, and organization of the web page. •Open standards and Open source
XML •Distributed.
XML is an abbreviation of Extensible Markup •Mainly makes the use of Web Browser in order to provide a
Language. It mainly helps in order to define the single interface for many services.
common syntax in the semantic web. •Dynamic
Advantages of WWW •Interactive
Given below are the benefits offered by WWW: •Cross-Platform
• It mainly provides all the information for Disadvantages of WWW
Free. There are some drawbacks of the WWW and these are as
• Provides rapid Interactive way of follows;
Communication. •It is difficult to prioritize and filter some information.
• It is accessible from anywhere. •There is no guarantee of finding what one person is looking
• It has become the Global source of media. for.
• It mainly facilitates the exchange of a huge •There occurs some danger in case of overload of Information.
volume of data.
HTML Introduction
HTML Editors
A simple text editor is all you need to Step 1: Open Notepad (PC)
learn HTML. Windows 8 or later:
Learn HTML Using Notepad or Open the Start Screen (the window symbol at the bottom left on your
TextEdit screen). Type Notepad.
Web pages can be created and Windows 7 or earlier:
modified by using professional HTML Open Start > Programs > Accessories > Notepad
editors. Step 1: Open TextEdit (Mac)
However, for learning HTML we Open Finder > Applications > TextEdit
recommend a simple text editor like Also change some preferences to get the application to save files
Notepad (PC) or TextEdit (Mac). correctly. In Preferences > Format > choose "Plain Text"
We believe that using a simple text Then under "Open and Save", check the box that says "Display HTML files
editor is a good way to learn HTML. as HTML code instead of formatted text".
Follow the steps below to create Then open a new document to place the code.
your first web page with Notepad or <!DOCTYPE html>
TextEdit. <html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
HTML Basic Examples
In this chapter we will show some basic HTML The <!DOCTYPE> Declaration
examples. • The <!DOCTYPE> declaration represents the document type,
Don't worry if we use tags you have not and helps browsers to display web pages correctly.
learned about yet. • It must only appear once, at the top of the page (before any
HTML Documents HTML tags).
All HTML documents must start with a • The <!DOCTYPE> declaration is not case sensitive.
document type declaration: <!DOCTYPE • The <!DOCTYPE> declaration for HTML5 is:
html>. <!DOCTYPE html>
The HTML document itself begins with HTML Headings
<html> and ends with </html>. HTML headings are defined with the <h1> to <h6> tags.
The visible part of the HTML document is <h1> defines the most important heading. <h6> defines the least
between <body> and </body>. important heading:
<!DOCTYPE html> Example
<!DOCTYPE html>
<html> <html>
<body> <body>
<h1>This is heading 1</h1>
<h1>COMM-IT</h1> <h2>This is heading 2</h2>
<p>IVS.</p> <h3>This is heading 3</h3>
<h4>This is heading 4</h4>
</body> <h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</html> </body>
</html>
HTML Basic Examples
HTML Paragraphs
HTML Images
HTML paragraphs are defined with the <p> tag:
HTML images are defined with the <img> tag.
<!DOCTYPE html>
The source file (src), alternative text (alt), width, and height are
<html>
provided as attributes:
<body>
Example
<p>This is a paragraph.</p>
<img src=“comm.jpg" alt=“google.com" width="104"
<p>This is another paragraph.</p>
height="142">
</body>
View HTML Source Code:
</html>
Right-click in an HTML page and select "View Page Source" (in
HTML Links
Chrome) or "View Source" (in Edge), or similar in other
HTML links are defined with the <a> tag:
browsers. This will open a window containing the HTML source
Example
code of the page.
<a
Inspect an HTML Element:
href="https://www.google.com.com">This
Right-click on an element (or a blank area), and choose
is a link</a>
"Inspect" or "Inspect Element" to see what elements are made
The link's destination is specified in the
up of (you will see both the HTML and the CSS). You can also
href attribute.
edit the HTML or CSS on-the-fly in the Elements or Styles panel
Attributes are used to provide additional
that opens.
information about HTML elements.
HTML Basic Examples
HTML headings are titles or subtitles that Users often skim a page by its headings. It is important to use
you want to display on a webpage. headings to show the document structure.
HTML Headings <h1> headings should be used for main headings, followed by <h2>
HTML headings are defined with the <h1> to headings, then the less important <h3>, and so on.
<h6> tags. Note: Use HTML headings for headings only. Don't use headings to
<h1> defines the most important heading. make text BIG or bold.
<h6> defines the least important heading. Bigger Headings
Example Each HTML heading has a default size. However, you can specify the
<h1>Heading 1</h1> size for any heading with the style attribute, using the CSS font-size
<h2>Heading 2</h2> property:
<h3>Heading 3</h3> Example
<h4>Heading 4</h4> <!DOCTYPE html>
<h5>Heading 5</h5> <html>
<h6>Heading 6</h6> <body>
Note: Browsers automatically add some <h1 style="font-size:60px;">Heading 1</h1>
white space (a margin) before and after a <p>You can change the size of a heading with the style attribute,
heading. using the font-size property.</p>
Headings Are Important </body>
Search engines use the headings to index the </html>
structure and content of your web pages.
HTML Headings
HTML Paragraphs HTML Horizontal Rules
The HTML <p> element defines a paragraph. The <hr> tag defines a thematic break in an HTML page, and
A paragraph always starts on a new line, and browsers is most often displayed as a horizontal rule.
automatically add some white space (a margin) before The <hr> element is used to separate content (or define a
and after a paragraph. change) in an HTML page:
Example <!DOCTYPE html>
<!DOCTYPE html> <html>
<html> <body>
<body> <h1>This is heading 1</h1>
<p>This is a paragraph.</p> <p>This is some text.</p>
<p>This is a paragraph.</p> <hr>
<p>This is a paragraph.</p> <h2>This is heading 2</h2>
</body> <p>This is some other text.</p>
HTML Display <hr>
You cannot be sure how HTML will be displayed. <h2>This is heading 2</h2>
Large or small screens, and resized windows will <p>This is some other text.</p>
create different results. </body>
With HTML, you cannot change the display by adding </html
extra spaces or extra lines in your HTML code. The <hr> tag is an empty tag, which means that it has no
The browser will automatically remove any extra end tag.
spaces and lines when the page is displayed:
HTML Line Breaks
The HTML <br> element defines a line break.
Use <br> if you want a line break (a new line) without starting a new paragraph:
Example
<p>This is<br>a paragraph<br>with line breaks.</p>
The HTML <pre> Element
The HTML <pre> element defines preformatted text.
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and
line breaks:
<!DOCTYPE html>
<html>
<body>
<p>The pre tag preserves both spaces and line breaks:</p>
<pre>
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
</pre>
</body>
</html>
HTML Styles
HTML comments are not displayed in the browser, but they can help document your HTML source code.
HTML Comment Tag
You can add comments to your HTML source by using the following syntax
<!-- Write your comments here -->
Notice that there is an exclamation point (!) in the start tag, but not in the end tag.
Note: Comments are not displayed by the browser, but they can help document your HTML source code.
Add Comments
With comments you can place notifications and reminders in your HTML code:
<!DOCTYPE html>
<html> Example
<body> <p>This is a paragraph.</p>
<!-- This is a comment --> <!-- <p>This is another paragraph </p> -->
<p>This is a paragraph.</p> <p>This is a paragraph too.</p>
<!-- Comments are not displayed in the browser --> Hide Inline Content
</body> Comments can be used to hide parts in the middle of
</html the HTML code.
Hide Content Example
Comments can be used to hide content. Hide a part of a paragraph:
This can be helpful if you hide content temporarily: <p>This <!-- great text --> is a paragraph.</p>
HTML Colors
HTML colors are specified with predefined color names, Text Color
or with RGB, HEX, HSL, RGBA, or HSLA values. You can set the color of text:
Color Names Example
In HTML, a color can be specified by using a color name: <h1 style="color:Tomato;">Hello World</h1>
• Tomato <p style="color:DodgerBlue;">Lorem ipsum...</p>
• Orange <p style="color:MediumSeaGreen;">Ut wisi enim...</p>
• Dodger Blue Border Color
• MediumSeaGreen You can set the color of borders:
• Gray
• Slate Blue <h1 style="border:2px solid Tomato;">Hello World</h1>
• Violet <h1 style="border:2px solid DodgerBlue;">Hello
• Light Gray
HTML supports 140 standard color names. World</h1>
Background Color <h1 style="border:2px solid Violet;">Hello World</h1>
You can set the background color for HTML elements:
Color Values
Example
In HTML, colors can also be specified using RGB values, HEX
<h1 style="background-color:DodgerBlue;">Hello
values, HSL values, RGBA values, and HSLA values.
World</h1>
The following three <div> elements have their background
<p style="background-color:Tomato;">Lorem
color set with RGB, HEX, and HSL values:
ipsum...</p>
HTML Colors
HTML RGB and RGBA Colors
An RGB color value represents RED, GREEN, and BLUE light sources.
An RGBA color value is an extension of RGB with an Alpha channel (opacity).
RGB Color Values
In HTML, a color can be specified as an RGB value, using this formula:
rgb(red, green, blue)
Each parameter (red, green, and blue) defines the intensity of the color with a value between 0 and 255.
This means that there are 256 x 256 x 256 = 16777216 possible colors!
For example, rgb(255, 0, 0) is displayed as red, because red is set to its highest value (255), and the other two
(green and blue) are set to 0.
Another example, rgb(0, 255, 0) is displayed as green, because green is set to its highest value (255), and the
other two (red and blue) are set to 0.
To display black, set all color parameters to 0, like this: rgb(0, 0, 0).
To display white, set all color parameters to 255, like this: rgb(255, 255, 255).
rgb(255, 0, 0)
rgb(0, 0, 255)
rgb(60, 179, 113)
rgb(238, 130, 238)
rgb(255, 165, 0)
rgb(106, 90, 205)
HTML Colors
Shades of Gray
Shades of gray are often defined using equal values for all three parameters:
rgb(60, 60, 60)
rgb(100, 100, 100)
rgb(140, 140, 140)
rgb(180, 180, 180)
rgb(200, 200, 200)
rgb(240, 240, 240)
RGBA Color Values
RGBA color values are an extension of RGB color values with an Alpha channel - which specifies the opacity for a
color.
An RGBA color value is specified with:
rgba(red, green, blue, alpha)
The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all):
Experiment by mixing the RGBA values below:
rgba(255, 99, 71, 0)
rgba(255, 99, 71, 0.2)
rgba(255, 99, 71, 0.4)
rgba(255, 99, 71, 0.6)
rgba(255, 99, 71, 0.8)
rgba(255, 99, 71, 1)
HTML Colors
HTML HEX Colors
A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers
specify the components of the color.
HEX Color Values
In HTML, a color can be specified using a hexadecimal value in the form:
#rrggbb
Where rr (red), gg (green) and bb (blue) are hexadecimal values between 00 and ff (same as decimal 0-255).
For example, #ff0000 is displayed as red, because red is set to its highest value (ff), and the other two (green and
blue) are set to 00.
Another example, #00ff00 is displayed as green, because green is set to its highest value (ff), and the other two (red
and blue) are set to 00.
To display black, set all color parameters to 00, like this: #000000.
To display white, set all color parameters to ff, like this: #ffffff.
Shades of Gray
Shades of gray are often defined using equal values for all three parameters:
Example
#404040
#686868
#a0a0a0
#bebebe
#dcdcdc
#f8f8f8
HTML Colors
HSLA Color Values
HSLA color values are an extension of HSL color values, with an Alpha channel - which specifies the opacity for a
color.
An HSLA color value is specified with:
hsla(hue, saturation, lightness, alpha)
The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all):
Experiment by mixing the HSLA values below:
hsla(0, 100%, 50%, 0.5)
hsla(9, 100%, 64%, 0)
hsla(9, 100%, 64%, 0.2)
hsla(9, 100%, 64%, 0.4)
hsla(9, 100%, 64%, 0.6)
hsla(9, 100%, 64%, 0.8)
hsla(9, 100%, 64%, 1)
HTML Styles - CSS
CSS stands for Cascading Style Sheets.
CSS saves a lot of work. It can control the layout of multiple web pages all at once.
What is CSS?
Cascading Style Sheets (CSS) is used to format the layout of a webpage.
With CSS, you can control the color, font, the size of text, the spacing between elements, how elements are
positioned and laid out, what background images or background colors are to be used, different displays for different
devices and screen sizes, and much more!
Tip: The word cascading means that a style applied to a parent element will also apply to all children elements within
the parent. So, if you set the color of the body text to "blue", all headings, paragraphs, and other text elements within
the body will also get the same color (unless you specify something else)!
Using CSS
CSS can be added to HTML documents in 3 ways:
Inline - by using the style attribute inside HTML elements
Internal - by using a <style> element in the <head> section
External - by using a <link> element to link to an external CSS file
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue, and the text color of the <p> element to red:
HTML Styles - CSS
Example
<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>
Internal CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within a <style> element.
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
HTML Styles - CSS
CSS Padding
The CSS padding property defines a padding <!DOCTYPE html> <!DOCTYPE html>
(space) between the text and the border. <html> <html>
Example <head> <head>
Use of CSS border and padding properties: <style> <style>
p{ p{ p{
border: 2px solid powderblue; border: 2px solid powderblue; border: 2px solid powderblue;
padding: 30px; padding: 30px; margin: 50px;
} } }
CSS Margin </style> </style>
The CSS margin property defines a margin </head> </head>
(space) outside the border. <body> <body>
Example <h1>This is a heading</h1> <h1>This is a heading</h1>
Use of CSS border and margin properties: <p>This is a paragraph.</p> <p>This is a paragraph.</p>
p{ <p>This is a paragraph.</p> <p>This is a paragraph.</p>
border: 2px solid powderblue; <p>This is a paragraph.</p> <p>This is a paragraph.</p>
margin: 50px; </body> </body>
} </html> </html>
HTML Styles - CSS
!DOCTYPE html>
<html> <tr>
<style> <td>16</td>
table, th, td { <td>14</td>
border:1px solid black; <td>10</td>
} </tr>
</style> </table>
<body> <p>To understand the example better, we have added
<h2>TH elements define table headers</h2> borders to the table.</p>
<table style="width:100%"> </body>
<tr> </html>
<th>Person 1</th>
<th>Person 2</th>
<th>Person 3</th>
</tr>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
HTML Tables
Tag Description
<!DOCTYPE html>
<!DOCTYPE html> <ul> Defines an unordered list
<html>
<html> <ol> Defines an ordered list
<body>
<body> <li> Defines a list item
<h2>An unordered HTML list</h2>
<h2>A Description List</h2> <dl> Defines a description list
<ul>
<dl> <dt> Defines a term in a description list
<li>Coffee</li>
<dt>Coffee</dt> <dd> Describes the term in a description list
<li>Tea</li>
<dd>- black hot drink</dd> HTML Unordered Lists <li>Milk</li>
<dt>Milk</dt> The HTML <ul> tag defines an unordered </ul>
<dd>- white cold drink</dd> (bulleted) list. </body>
</dl> Unordered HTML List </html>
</body> An unordered list starts with the <ul> tag.
</html Each list item starts with the <li> tag.
The list items will be marked with bullets
(small black circles) by default:
HTML LIST
History of JavaScript
In 1993, Mosaic, the first popular web browser, came into existence. In the year 1994, Netscape was founded by Marc
Andreessen. He realized that the web needed to become more dynamic. Thus, a 'glue language' was believed to be
provided to HTML to make web designing easy for designers and part-time programmers. Consequently, in 1995, the
company recruited Brendan Eich intending to implement and embed Scheme programming language to the browser.
But, before Brendan could start, the company merged with Sun Microsystems for adding Java into its Navigator so
that it could compete with Microsoft over the web technologies and platforms. Now, two languages were there: Java
and the scripting language. Further, Netscape decided to give a similar name to the scripting language as Java's. It led
to 'Javascript'. Finally, in May 1995, Marc Andreessen coined the first code of Javascript named 'Mocha'. Later, the
marketing team replaced the name with 'LiveScript'. But, due to trademark reasons and certain other reasons, in
December 1995, the language was finally renamed to 'JavaScript'. From then, JavaScript came into existence.
Application of JavaScript
JavaScript is used to create interactive websites. It is mainly used for:
• Client-side validation,
• Dynamic drop-down menus,
• Displaying date and time,
• Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog box and prompt dialog box),
• Displaying clocks etc.
Introduction of Java Script
History of JavaScript
In 1993, Mosaic, the first popular web browser, came into existence. In the year 1994, Netscape was founded by Marc
Andreessen. He realized that the web needed to become more dynamic. Thus, a 'glue language' was believed to be
provided to HTML to make web designing easy for designers and part-time programmers. Consequently, in 1995, the
company recruited Brendan Eich intending to implement and embed Scheme programming language to the browser.
But, before Brendan could start, the company merged with Sun Microsystems for adding Java into its Navigator so
that it could compete with Microsoft over the web technologies and platforms. Now, two languages were there: Java
and the scripting language. Further, Netscape decided to give a similar name to the scripting language as Java's. It led
to 'Javascript'. Finally, in May 1995, Marc Andreessen coined the first code of Javascript named 'Mocha'. Later, the
marketing team replaced the name with 'LiveScript'. But, due to trademark reasons and certain other reasons, in
December 1995, the language was finally renamed to 'JavaScript'. From then, JavaScript came into existence.
Application of JavaScript
JavaScript is used to create interactive websites. It is mainly used for:
• Client-side validation,
• Dynamic drop-down menus,
• Displaying date and time,
• Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog box and prompt dialog box),
• Displaying clocks etc.
Introduction of Java Script
JavaScript Example
• Within body tag
• Within head tag
Javascript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within
head tag and external JavaScript file.
<script type="text/javascript">
document.write("JavaScript is a simple language for BCA Ist SEM");
</script
The script tag specifies that we are using JavaScript.
The text/javascript is the content type that provides information to the browser about the data.
The document.write() function is used to display dynamic content through JavaScript. We will learn about document
object in detail later.
Places to put JavaScript code
• Between the body tag of html
• Between the head tag of html
• In .js file (external javaScript)
Introduction of Java Script
JavaScript Example : code between the body tag
<script type="text/javascript">
alert("Hello ");
</script>
JavaScript Example : code between the head tag
<html>
<head>
<script type="text/javascript">
function msg(){
alert("Hello ");
}
</script>
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="msg()"/>
</form>
</body>
</html>
Introduction of Java Script
JavaScript Operators
JavaScript operators are symbols that are used to perform operations on operands. For example:
+ Addition 10+20 = 30
- Subtraction 20-10 = 10
* Multiplication 10*20 = 200
/ Division 20/10 = 2
% Modulus (Remainder) 20%10 = 0
++ Increment var a=10; a++; Now a =
11
-- Decrement var a=10; a--; Now a = 9
Javascript Data Types
JavaScript Comparison Operators JavaScript Bitwise Operators
The JavaScript comparison operator compares The bitwise operators perform bitwise operations on operands.
the two operands. The comparison operators The bitwise operators are as follows:
are as follows:
Operator Description Example Operator Description Example
<= Less than or equal 20<=10 = false >>> Bitwise Right Shift (10>>>2) = 2
to with Zero
Javascript Data Types
<!DOCTYPE html>
Object Properties
<html>
The name:values pairs in JavaScript objects are called properties: <body>
Property :Property Value <h2>JavaScript Objects</h2>
firstName:John <p>There are two different ways to access an object
lastName :Doe property.</p>
<p>You can use person.property or
age:50
person["property"].</p>
eyeColor: blue <p id="demo"></p>
Accessing Object Properties <script>
You can access object properties in two ways: // Create an object:
objectName.propertyName const person = {
objectName["propertyName"] firstName: "John",
Example1 lastName : "Doe",
id : 5566
};
// Display some data from the object:
document.getElementById("demo").innerHTML =
person.firstName + " " + person.lastName;
</script>
</body>
</html>
JavaScript Objects
<!DOCTYPE html>
<html> Object Methods
<body> Objects can also have methods.
<h2>JavaScript Objects</h2> Methods are actions that can be performed on
<p>There are two different ways to access an object objects.
property.</p> Methods are stored in properties as function
<p>You can use person.property or person["property"].</p> definitions.
<p id="demo"></p> A method is a function stored as a property.
<script> Property Property Value
// Create an object:
const person = { firstName John
firstName: "John",
lastName : "Doe", lastName Doe
id : 5566
}; age 50
// Display some data from the object:
document.getElementById("demo").innerHTML = eyeColor blue
person["firstName"] + " " + person["lastName"];
</script> fullName function() {return this.firstName + "
JavaScript objects are containers for named values called " + this.lastName;}
properties.
JavaScript Objects
Example
What is this?
const person = {
In JavaScript, the this keyword refers to an object.
firstName: "John",
Which object depends on how this is being invoked (used or
lastName : "Doe",
called).
id : 5566,
The this keyword refers to different objects depending on how
fullName : function() {
it is used:
return this.firstName + " " + this.lastName;
}
}; In an object method, this refers to the object.
In the example above, this refers to the person Alone, this refers to the global object.
object.
I.E. this.firstName means the firstName property In a function, this refers to the global object.
of this. In a function, in strict mode, this is undefined.
I.E. this.firstName means the firstName property
of person. In an event, this refers to the element that received the event.
Note
this is not a variable. It is a keyword. You cannot Methods like call(), apply(), and bind() can refer this to any
change the value of this. object.
JavaScript Objects
The this Keyword
<!DOCTYPE html>
In a function definition, this refers to the
<html>
"owner" of the function. <body>
In the example above, this is the person <h2>JavaScript Objects</h2>
object that "owns" the fullName function. <p>An object method is a function definition, stored as a property
In other words, this.firstName means the value.</p>
firstName property of this object. <p id="demo"></p>
Accessing Object Methods <script>
You access an object method with the // Create an object:
const person = {
following syntax:
firstName: "John",
objectName.methodName() lastName: "Doe",
Example id: 5566,
name = person.fullName(); fullName: function() {
return this.firstName + " " + this.lastName;
}
};
// Display data from the object:
document.getElementById("demo").innerHTML = person.fullName();
</script>
</body>
</html>
JavaScript Objects
If you access a method without the () parentheses, it will return the function
definition:
<!DOCTYPE html>
<html> Do Not Declare Strings, Numbers, and Booleans as
<body> Objects!
<h2>JavaScript Objects</h2>
<p>If you access an object method without (), it will return the function
definition:</p> When a JavaScript variable is declared with the
<p id="demo"></p> keyword "new", the variable is created as an
<script> object:
// Create an object:
const person = { x = new String(); // Declares x as a String
firstName: "John", object
lastName : "Doe", y = new Number(); // Declares y as a
id : 5566,
fullName : function() {
Number object
return this.firstName + " " + this.lastName; z = new Boolean(); // Declares z as a Boolean
} object
}; Avoid String, Number, and Boolean objects.
// Display data from the object:
document.getElementById("demo").innerHTML = person.fullName; They complicate your code and slow down
</script> execution speed.
</body>
</html>
Java Handling Events
The change in the state of an object is known as an Event. In html, there are various events which represents
that some activity is performed by the user or by the browser. When javascript code is included in HTML, js
react over these events and allow the execution. This process of reacting over the events is called Event
Handling. Thus, js handles the HTML events via Event Handlers.
For example, when a user clicks over the browser, add js code, which will execute the task to be performed on
the event.
Some of the HTML events and their event handlers are:
Mouse events:
Event Performed Event Handler Description
Keydown & Keyup onkeydown & onkeyup When the user press and then release
the key
Form events:
Event Performed Event Handler Description
Window/Document events
Number Methods
1 constructor()Returns the function that created this object's instance. By default this is the Number object.
toExponential()Forces a number to display in exponential notation, even if the number is in the range in which JavaScript
2
normally uses standard notation.
3 toFixed()Formats a number with a specific number of digits to the right of the decimal.
toLocaleString()Returns a string value version of the current number in a format that may vary according to a browser's locale
4
settings.
5 toPrecision()Defines how many total digits (including digits to the left and right of the decimal) to display of a number.
Boolean Methods
toSource()Returns a string containing the source of the Boolean object; you can use this string to create an
1
equivalent object.
2 toString()Returns a string of either "true" or "false" depending upon the value of the object.
1. HTML is simply a markup language. 1. DHTML is not a language, but it is a set of technologies of web
development.
2. It is used for developing and creating web pages. 2. It is used for creating and designing the animated and interactive
web sites or pages.
3. This markup language creates static web pages. 3. This concept creates dynamic web pages.
4. It does not contain any server-side scripting code. 4. It may contain the code of server-side scripting.
5. The files of HTML are stored with the .html or .htm extension in a 5. The files of DHTML are stored with the .dhtm extension in a
system. system.
6. A simple page which is created by a user without using the scripts 6. A page which is created by a user using the HTML, CSS, DOM,
or styles called as an HTML page. and JavaScript technologies called a DHTML page.
7. This markup language does not need database connectivity. 7. This concept needs database connectivity because it interacts
with users.
Unit-3DHTML JavaScript
DHTML JavaScript
JavaScript can be included in HTML pages, which creates the content of the page as dynamic. We can easily type
the JavaScript code within the <head> or <body> tag of a HTML page. If we want to add the external source file of
JavaScript, we can easily add using the <src> attribute.
Following are the various examples, which describes how to use the JavaScript technology with the DHTML:
Document.write() Method
The document.write() method of JavaScript, writes the output to a web page.
Example 1: The following example simply uses the document.write() method of JavaScript in the DHTML. In this
example, we type the JavaScript code in the <body> tag. Example-1
<HTML>
<head>
<title>
Method of a JavaScript
</title>
</head>
<body>
<script type="text/javascript">
document.write("Java script");
</script>
</body>
</html>
Unit-3DHTML JavaScript
JavaScript and HTML event <html>
A JavaScript code can also be <head>
executed when some event occurs. <title>
Suppose, a user clicks an HTML DHTML with JavaScript
element on a webpage, and after </title>
clicking, the JavaScript function <script type="text/javascript">
associated with that HTML element function dateandtime()
{
is automatically invoked. And, then
alert(Date());
the statements in the function are
}
performed. </script>
Example 1: The following example </head>
shows the current date and time <body bgcolor="orange">
with the JavaScript and HTML <font size="4" color="blue">
event (Onclick). In this example, we <center> <p>
type the JavaScript code in the Click here # <a href="#" onClick="dateandtime();"> Date and Time </a>
<head> tag. # to check the today's date and time.
</p> </center>
</font>
</body>
</html>
Unit-3 JavaScript and HTML DOM
With version 4 of HTML, JavaScript code can also change the inner content and attributes of the HTML event.
Example 1: This example checks the Grade of a student according to the percentage criteria with the
JavaScript and HTML DOM. In this example, we type the code of a JavaScript in the <body> tag.
With version 4 of HTML, JavaScript code can also change the style such as size, color, and face of an HTML
element.
<html>
<head>
<title>
getElementById.style.property example
</title>
</head>
<body>
<p id="demo"> This text changes color when click on the following different buttons. </p>
<button onclick="change_Color('green');"> Green </button>
<button onclick="change_Color('blue');"> Blue </button>
<script type="text/javascript">
function change_Color(newColor) {
var element = document.getElementById('demo').style.color = newColor;
}
</script>
</body>
</html>
Unit-3 CSS with JavaScript in DHTML
With version 4 of HTML, JavaScript code can also change the style such as size, color, and face of an HTML element.
<html>
<head>
<title>
getElementById.style.property example
</title>
</head>
<body>
<p id="demo"> This text changes color when click on the following different buttons. </p>
<button onclick="change_Color('green');"> Green </button>
<button onclick="change_Color('blue');"> Blue </button>
<script type="text/javascript">
function change_Color(newColor) {
var element = document.getElementById('demo').style.color = newColor;
}
</script>
</body>
</html>
In the above code, we changed the color of a text by using the following syntax:
document.getElementById('demo').style.property=new_value;.
The above syntax is used in the JavaScript function, which is performed or called when we clicked on the HTML buttons. The
different HTML buttons specify the color of a text.
Unit-3 CSS with JavaScript in DHTML
DHTML CSS
We can easily use the CSS with the DHTML page with the help of JavaScript and HTML DOM. With the help of
this.style.property=new style statement, we can change the style of the currently used HTML element. Or, we
can also update the style of any particular HTML element by document.getElementById(id).style.property =
new_style statement.
Example 1
<html>
<head>
<title>
Changes current HTML element
</title>
</head>
<body>
<center>
<h1 onclick="this.style.color='blue'"> This is Css in DHTML </h1>
<center>
</body>
</html>
Unit-3 CSS with JavaScript in DHTML
Example 2: The following example uses the DHTML CSS for changing the style of the HTML element:
<html>
<head>
<title>
changes the particular HTML element example
</title>
</head>
<body>
<p id="demo"> This text changes color when click on the following different buttons. </p>
<button onclick="change_Color('green');"> Green </button>
<button onclick="change_Color('blue');"> Blue </button>
<script type="text/javascript">
function change_Color(newColor) {
var element = document.getElementById('demo').style.color = newColor;
}
</script>
</body>
</html>
Unit-3 CSS with JavaScript in DHTML
Example 2: The following example uses the DHTML CSS for changing the style of the HTML element:
<html>
<head>
<title>
changes the particular HTML element example
</title>
</head>
<body>
<p id="demo"> This text changes color when click on the following different buttons. </p>
<button onclick="change_Color('green');"> Green </button>
<button onclick="change_Color('blue');"> Blue </button>
<script type="text/javascript">
function change_Color(newColor) {
var element = document.getElementById('demo').style.color = newColor;
}
</script>
</body>
</html>
Unit-3 CSS with JavaScript in DHTML
DHTML Events
An event is defined as changing the
S.No. Event When it occurs
occurrence of an object.
It is compulsory to add the events in the 1. onabort It occurs when the user aborts the page or media file loading.
DHTML page. Without events, there will be
no dynamic content on the HTML page. The
2. onblur It occurs when the user leaves an HTML object.
event is a term in the HTML, which triggers
the actions in the web browsers.
3. onchange It occurs when the user changes or updates the value of an
Suppose, any user clicks an HTML element, object.
then the JavaScript code associated with
that element is executed. Actually, the event 4. onclick It occurs or triggers when any user clicks on an HTML element.
handlers catch the events performed by the
user and then execute the code.
Example of events: 5. ondblclick It occurs when the user clicks on an HTML element two times
together.
• Click a button.
• Submitting a form.
6. onfocus It occurs when the user focuses on an HTML element. This
• An image loading or a web page loading, event handler works opposite to onblur.
etc.
Unit-3 CSS with JavaScript in DHTML
7. onkeydown It triggers when a user is pressing a key on a keyboard device. This event handler works for all the keys.
8. onkeypress It triggers when the users press a key on a keyboard. This event handler is not triggered for all the keys.
9. onkeyup It occurs when a user released a key from a keyboard after pressing on an object or element.
11. onmousedown It occurs when a user presses the button of a mouse over an HTML element.
12. onmousemove It occurs when a user moves the cursor on an HTML object.
13. onmouseover It occurs when a user moves the cursor over an HTML object.
14. onmouseout It occurs or triggers when the mouse pointer is moved out of an HTML element.
15. onmouseup It occurs or triggers when the mouse button is released over an HTML element.
18. onsubmit It is triggered when the user clicks a button after the submission of a form.
Advantages of DHTML
Following are the various benefits or the advantages of DHTML (Dynamic HTML):
• Those web sites and web pages which are created using this concept are fast.
• There is no plug-in required for creating the web page dynamically.
• Due to the low-bandwidth effect by the dynamic HTML, the web page functionality is enhanced.
• This concept provides advanced functionalities than the static HTML.
• It is highly flexible, and the user can make changes easily in the web pages.
Disadvantages of DHTML
• Following are the various disadvantages or limitations of DHTML (Dynamic HTML):
• The scripts of DHTML does not run properly in various web browsers. Or in simple words, we can say that various
web browsers do not support the DHTML. It is only supported by the latest browsers.
• The coding of those websites that are created using DHTML is long and complex.
• For understanding the DHTML, users must know about HTML, CSS, and JavaScript. If any user does not know
these languages, then it is a time-consuming and long process in itself.