This document provides an overview of JavaScript and the Document Object Model (DOM). It discusses how the DOM represents an HTML document as nodes that can be manipulated with JavaScript. Key points covered include finding and changing HTML elements, modifying attributes and styles, handling events, and navigating the node tree. The Browser Object Model is also introduced, with the window object representing the browser window. Methods for creating and adding new DOM nodes are demonstrated.
The document discusses the Document Object Model (DOM) and how it allows programs and scripts to dynamically access and update the content, structure, and style of an HTML or XML document. It defines the DOM as a standard set by the W3C. The document then discusses the DOM for HTML documents (HTML DOM) and how it defines HTML elements as objects and provides properties and methods to access and modify those elements. It also discusses DOM events and how they allow JavaScript to add event handlers to HTML elements for user interactions.
JavaScript is a scripting language that allows adding interactivity to HTML pages. It can react to events, read and write HTML elements, validate data, detect the visitor's browser, create cookies, and more. The DOM defines a standard for accessing and manipulating HTML documents. JavaScript uses objects, functions, and prototypes for object-oriented programming. Key concepts include encapsulation, inheritance, and abstraction. Events follow the capturing and bubbling phases. JavaScript supports conditionals, loops, functions, scopes, closures, and more.
This document discusses HTML collections and event handling in JavaScript. It provides examples of how to access elements in HTML collections using methods like getElementsByTagName. It also covers different types of events like click, mouseover, form submit and how to attach event handlers using inline, traditional and modern approaches. It discusses timing events like setTimeout and setInterval. Finally it covers event propagation models of bubbling and capturing.
Unit ii java script and xhtml documents and dynamic documents with javascriptzahid7578
The document discusses the JavaScript execution environment and the Document Object Model (DOM). It describes:
1. How a browser displays an XHTML document and how JavaScript interacts with the window and document objects.
2. The evolution of the DOM standard from DOM 0 to DOM 3 and how it provides a mapping of web documents to JavaScript objects.
3. How events are handled in JavaScript, including the basic concepts of events, event handlers, and the DOM 0 and DOM 2 event models.
Learning About JavaScript (…and its little buddy, JQuery!)Julie Meloni
Slides from an internal workshop at the GWU Library on 26 June 2012. The workshop was organized into three parts: "Understanding JavaScript Basics", "About the DOM (Document Object Model)", and "Where JQuery Fits in and How it Works".
Dom date and objects and event handlingsmitha273566
The document discusses the JavaScript Document Object Model (DOM) and regular expressions. It defines the DOM as a programming interface for HTML and XML documents that defines the logical structure and allows manipulation. It describes how the DOM represents an HTML document as a tree of nodes that can be accessed and modified with JavaScript. It provides examples of how to select elements, modify attributes and content, add and remove nodes, and handle events. Regular expressions are also mentioned as a topic.
The document provides information about JavaScript and the Document Object Model (DOM). It discusses how JavaScript can dynamically access and update HTML elements using the DOM. It explains that all HTML elements are defined as objects in the DOM that can be accessed and manipulated using JavaScript properties and methods. The document provides examples of how to select elements, modify attributes and styles, add and remove elements, and handle events. It also covers common JavaScript objects like Date, Math, and built-in constructors.
The document describes the Document Object Model (DOM) and how it allows JavaScript to dynamically access and update the content, structure, and style of an HTML document. It explains that the DOM represents an HTML document as nodes and objects, which JavaScript can manipulate by accessing and changing the document's properties and methods. The DOM defines elements as objects that JavaScript can select, add, and remove nodes from in order to dynamically modify an HTML document.
GDG On Campus NBNSCOE Web Development Workshop Day 2 : JavaScript and DOMudaymore742
In this session, we dive into the fundamentals of JavaScript ⚙ and explore DOM manipulation 🛠 to bring interactivity to your webpages.
📚 What You'll Learn:
JavaScript Basics: Variables, functions, and control structures.
DOM Manipulation: Select, modify, and create HTML elements dynamically.
Practical Examples: Hands-on coding to solidify your understanding.
💡 Whether you're a beginner or looking to enhance your skills, this session is packed with insights to level up your coding journey!
The document discusses the HTML Document Object Model (DOM). Key points include:
1) The DOM defines a standard object model and programming interface for HTML documents that allows JavaScript to access and modify HTML elements.
2) The DOM represents an HTML document as nodes and objects with a tree structure that can be accessed and manipulated.
3) JavaScript can get, change, add, or delete HTML elements using the DOM methods and properties to select elements, get/set their attributes and content, and handle events.
DOM(Document Object Model) in javascriptRashmi Mishra
Title: Mastering JavaScript: From Basics to Advanced
Description:
Enhance your JavaScript skills with our comprehensive presentation designed for both beginners and advanced learners. This detailed guide covers essential topics, including:
JavaScript Fundamentals: Variables, data types, functions, and loops
DOM Manipulation: Accessing and modifying HTML elements
Advanced Concepts: Closures, promises, async/await
Practical Examples: Real-world applications and coding exercises
Key Features:
Clear, concise explanations of key JavaScript concepts
High-quality visuals to aid understanding
Practical code examples and exercises
Links to additional resources and full study materials
Why You’ll Love This Presentation:
Perfect for self-learners and students
Great reference for developers at all levels
Continuously updated content to stay current with industry trends
Get the Full Study Materials:
Visit our website [YourWebsite.com] for the complete JavaScript study guide, detailed cheat sheets, and exclusive tutorials.
Join our newsletter for updates and special offers on our educational products.
The document provides information about Dynamic Hypertext Markup Language (DHTML). It discusses that DHTML is not a language itself but a combination of technologies including HTML, CSS, JavaScript, and DOM to make web pages dynamic and interactive. It then explains the four main components of DHTML and provides examples of using JavaScript, DOM, events, and CSS to manipulate HTML elements and create dynamic content. The document also covers advantages and disadvantages of DHTML.
The document discusses the basic web security model, including browser content, the document object model (DOM), and the same origin policy. It provides details on how HTTP works with requests and responses between clients and servers. It also explains how web browsers function to display web pages and render HTML content. The DOM is described as an API that allows programs to interact with HTML documents and define their structure as a hierarchical tree of objects. Event handling and the same origin policy, which restricts interactions between pages from different origins, are also summarized.
Build over 20 mini JavaScript Projects with full source code
https://skl.sh/3yJdYM0
Web Developer Setup use of Editor for JavaScript Code
JavaScript Projects DOM Interactive Dynamic web pages Introduction web development Course Resource Guide.
Getting started with JavaScript DOM coding and development
Web Developer Setup use of Editor for JavaScript Code
JavaScript Resources to explore more about JavaScript
JavaScript DOM Object Selecting Page elements and more
JavaScript querySelectorAll Get Page Elements Select ALL
Page Events Element Event Listener access page content with JavaScript
JavaScript and Page Input Values from Page Elements
How to use JavaScript Request Animation Frame
JavaScript Starter Projects DOM Simple Projects to Start Coding
How to make Interactive DOM list saving to localstorage
JavaScript Component Create a Star Rating Project
JavaScript Game within the DOM Coin Toss Game Project
JavaScript Typing Challenge Game with JavaScript DOM
JavaScript DOM fun with Page Elements Moving Storing Keypress
JavaScript Combo Guessing Game Exercise
JavaScript Shape Clicker Game Click the shape quickly to win
JavaScript Number Guessing Game with Game Logic
JavaScript DOM Interactive Components and Useful Projects
Pure JavaScript Accordion hide and show page elements
JavaScript Drag and Drop Simple Boxes Component
Dynamic Drag and Drop
JavaScript Email Extractor Mini Project
Create a Quiz with Javascript JSON quiz tracker
JavaScript Image Preview File Reader Example
JavaScript Interactive Dice Game with Page elements
JavaScript Dice Game Challenge Lesson
JavaScript DOM Fun Projects Interactive DOM Elements
JavaScript Tip Calculator Project
Tip Calculator Project Part 1
Tip Calculator Project Part 2
Pure JavaScript Calculator DOM page elements Project
JavaScript Calculator Part 1
JavaScript Calculator Part 2
JavaScript Calculator Part 3
JavaScript Bubble Popping DOM Game Coding project
How to move a Page Element With JavaScript DOM Mover Example
Collision Detection between Page elements with JavaScript DOM
JavaScript DOM Interactive Game
This document provides an overview of how to script the DOM using JavaScript. It discusses how the browser parses HTML into a DOM tree, with the window and document objects being the root nodes. It then explains how to access and manipulate DOM elements using the body, JavaScript functions, and events. Finally, it covers creating custom objects and namespacing in JavaScript.
This document provides an introduction to using JavaScript with XML and the Document Object Model (DOM). It explains that JavaScript can be used to dynamically access and modify XML documents by creating a DOM representation of the XML. The DOM exposes properties and methods to navigate and manipulate the XML document tree. Examples are given of how to load an XML file, access element values, attributes, and loop through nodes to retrieve and update the XML data programmatically.
Explains DOM and Events. HTML-Only DOM is explained and Form elements.
Events handling using element properties and event listeners is explained too.
A quick review on Cookies and referrer is briefed too
JavaScript can dynamically manipulate the content, structure, and styling of an HTML document through the Document Object Model (DOM). The DOM represents an HTML document as nodes that can be accessed and modified with JavaScript. Common tasks include dynamically creating and adding elements, handling user events like clicks, and updating content by accessing DOM elements by their id or other attributes.
What is the DOM?
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
The W3C DOM standard is separated into 3 different parts:
Core DOM - standard model for all document types
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects.
With the HTML DOM, JavaScript can access and change all the elements of an HTML document.
This document provides an overview of JavaScript including:
1. Why JavaScript is important for web development as one of the three main languages used along with HTML and CSS.
2. The different ways JavaScript can display data such as writing to HTML elements or using alerts.
3. Key JavaScript concepts such as variables, comments, functions, objects, and errors.
4. How JavaScript interacts with the DOM to modify HTML elements and handle events.
The document discusses HTMLCollection objects and JavaScript events. It explains that getElementsByTagName() returns an HTMLCollection containing element nodes that can be accessed by index. The length property defines the number of elements in an HTMLCollection. Examples are given to change the background color of all <p> elements in a collection and display the current time when a button is clicked. Common HTML events like onclick and onload are also described.
HOW YOU DOIN'?
Cool, cool, cool...
Because that's what she said after THE QUIZ CLUB OF PSGCAS' TV SHOW quiz.
Grab your popcorn and be seated.
QM: THARUN S A
BCom Accounting and Finance (2023-26)
THE QUIZ CLUB OF PSGCAS.
More Related Content
Similar to Document_Object_Model_in_javaScript..................................ppt (20)
The document provides information about JavaScript and the Document Object Model (DOM). It discusses how JavaScript can dynamically access and update HTML elements using the DOM. It explains that all HTML elements are defined as objects in the DOM that can be accessed and manipulated using JavaScript properties and methods. The document provides examples of how to select elements, modify attributes and styles, add and remove elements, and handle events. It also covers common JavaScript objects like Date, Math, and built-in constructors.
The document describes the Document Object Model (DOM) and how it allows JavaScript to dynamically access and update the content, structure, and style of an HTML document. It explains that the DOM represents an HTML document as nodes and objects, which JavaScript can manipulate by accessing and changing the document's properties and methods. The DOM defines elements as objects that JavaScript can select, add, and remove nodes from in order to dynamically modify an HTML document.
GDG On Campus NBNSCOE Web Development Workshop Day 2 : JavaScript and DOMudaymore742
In this session, we dive into the fundamentals of JavaScript ⚙ and explore DOM manipulation 🛠 to bring interactivity to your webpages.
📚 What You'll Learn:
JavaScript Basics: Variables, functions, and control structures.
DOM Manipulation: Select, modify, and create HTML elements dynamically.
Practical Examples: Hands-on coding to solidify your understanding.
💡 Whether you're a beginner or looking to enhance your skills, this session is packed with insights to level up your coding journey!
The document discusses the HTML Document Object Model (DOM). Key points include:
1) The DOM defines a standard object model and programming interface for HTML documents that allows JavaScript to access and modify HTML elements.
2) The DOM represents an HTML document as nodes and objects with a tree structure that can be accessed and manipulated.
3) JavaScript can get, change, add, or delete HTML elements using the DOM methods and properties to select elements, get/set their attributes and content, and handle events.
DOM(Document Object Model) in javascriptRashmi Mishra
Title: Mastering JavaScript: From Basics to Advanced
Description:
Enhance your JavaScript skills with our comprehensive presentation designed for both beginners and advanced learners. This detailed guide covers essential topics, including:
JavaScript Fundamentals: Variables, data types, functions, and loops
DOM Manipulation: Accessing and modifying HTML elements
Advanced Concepts: Closures, promises, async/await
Practical Examples: Real-world applications and coding exercises
Key Features:
Clear, concise explanations of key JavaScript concepts
High-quality visuals to aid understanding
Practical code examples and exercises
Links to additional resources and full study materials
Why You’ll Love This Presentation:
Perfect for self-learners and students
Great reference for developers at all levels
Continuously updated content to stay current with industry trends
Get the Full Study Materials:
Visit our website [YourWebsite.com] for the complete JavaScript study guide, detailed cheat sheets, and exclusive tutorials.
Join our newsletter for updates and special offers on our educational products.
The document provides information about Dynamic Hypertext Markup Language (DHTML). It discusses that DHTML is not a language itself but a combination of technologies including HTML, CSS, JavaScript, and DOM to make web pages dynamic and interactive. It then explains the four main components of DHTML and provides examples of using JavaScript, DOM, events, and CSS to manipulate HTML elements and create dynamic content. The document also covers advantages and disadvantages of DHTML.
The document discusses the basic web security model, including browser content, the document object model (DOM), and the same origin policy. It provides details on how HTTP works with requests and responses between clients and servers. It also explains how web browsers function to display web pages and render HTML content. The DOM is described as an API that allows programs to interact with HTML documents and define their structure as a hierarchical tree of objects. Event handling and the same origin policy, which restricts interactions between pages from different origins, are also summarized.
Build over 20 mini JavaScript Projects with full source code
https://skl.sh/3yJdYM0
Web Developer Setup use of Editor for JavaScript Code
JavaScript Projects DOM Interactive Dynamic web pages Introduction web development Course Resource Guide.
Getting started with JavaScript DOM coding and development
Web Developer Setup use of Editor for JavaScript Code
JavaScript Resources to explore more about JavaScript
JavaScript DOM Object Selecting Page elements and more
JavaScript querySelectorAll Get Page Elements Select ALL
Page Events Element Event Listener access page content with JavaScript
JavaScript and Page Input Values from Page Elements
How to use JavaScript Request Animation Frame
JavaScript Starter Projects DOM Simple Projects to Start Coding
How to make Interactive DOM list saving to localstorage
JavaScript Component Create a Star Rating Project
JavaScript Game within the DOM Coin Toss Game Project
JavaScript Typing Challenge Game with JavaScript DOM
JavaScript DOM fun with Page Elements Moving Storing Keypress
JavaScript Combo Guessing Game Exercise
JavaScript Shape Clicker Game Click the shape quickly to win
JavaScript Number Guessing Game with Game Logic
JavaScript DOM Interactive Components and Useful Projects
Pure JavaScript Accordion hide and show page elements
JavaScript Drag and Drop Simple Boxes Component
Dynamic Drag and Drop
JavaScript Email Extractor Mini Project
Create a Quiz with Javascript JSON quiz tracker
JavaScript Image Preview File Reader Example
JavaScript Interactive Dice Game with Page elements
JavaScript Dice Game Challenge Lesson
JavaScript DOM Fun Projects Interactive DOM Elements
JavaScript Tip Calculator Project
Tip Calculator Project Part 1
Tip Calculator Project Part 2
Pure JavaScript Calculator DOM page elements Project
JavaScript Calculator Part 1
JavaScript Calculator Part 2
JavaScript Calculator Part 3
JavaScript Bubble Popping DOM Game Coding project
How to move a Page Element With JavaScript DOM Mover Example
Collision Detection between Page elements with JavaScript DOM
JavaScript DOM Interactive Game
This document provides an overview of how to script the DOM using JavaScript. It discusses how the browser parses HTML into a DOM tree, with the window and document objects being the root nodes. It then explains how to access and manipulate DOM elements using the body, JavaScript functions, and events. Finally, it covers creating custom objects and namespacing in JavaScript.
This document provides an introduction to using JavaScript with XML and the Document Object Model (DOM). It explains that JavaScript can be used to dynamically access and modify XML documents by creating a DOM representation of the XML. The DOM exposes properties and methods to navigate and manipulate the XML document tree. Examples are given of how to load an XML file, access element values, attributes, and loop through nodes to retrieve and update the XML data programmatically.
Explains DOM and Events. HTML-Only DOM is explained and Form elements.
Events handling using element properties and event listeners is explained too.
A quick review on Cookies and referrer is briefed too
JavaScript can dynamically manipulate the content, structure, and styling of an HTML document through the Document Object Model (DOM). The DOM represents an HTML document as nodes that can be accessed and modified with JavaScript. Common tasks include dynamically creating and adding elements, handling user events like clicks, and updating content by accessing DOM elements by their id or other attributes.
What is the DOM?
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
The W3C DOM standard is separated into 3 different parts:
Core DOM - standard model for all document types
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects.
With the HTML DOM, JavaScript can access and change all the elements of an HTML document.
This document provides an overview of JavaScript including:
1. Why JavaScript is important for web development as one of the three main languages used along with HTML and CSS.
2. The different ways JavaScript can display data such as writing to HTML elements or using alerts.
3. Key JavaScript concepts such as variables, comments, functions, objects, and errors.
4. How JavaScript interacts with the DOM to modify HTML elements and handle events.
The document discusses HTMLCollection objects and JavaScript events. It explains that getElementsByTagName() returns an HTMLCollection containing element nodes that can be accessed by index. The length property defines the number of elements in an HTMLCollection. Examples are given to change the background color of all <p> elements in a collection and display the current time when a button is clicked. Common HTML events like onclick and onload are also described.
HOW YOU DOIN'?
Cool, cool, cool...
Because that's what she said after THE QUIZ CLUB OF PSGCAS' TV SHOW quiz.
Grab your popcorn and be seated.
QM: THARUN S A
BCom Accounting and Finance (2023-26)
THE QUIZ CLUB OF PSGCAS.
Human Anatomy and Physiology II Unit 3 B pharm Sem 2
Respiratory system
Anatomy of respiratory system with special reference to anatomy
of lungs, mechanism of respiration, regulation of respiration
Lung Volumes and capacities transport of respiratory gases,
artificial respiration, and resuscitation methods
Urinary system
Anatomy of urinary tract with special reference to anatomy of
kidney and nephrons, functions of kidney and urinary tract,
physiology of urine formation, micturition reflex and role of
kidneys in acid base balance, role of RAS in kidney and
disorders of kidney
RE-LIVE THE EUPHORIA!!!!
The Quiz club of PSGCAS brings to you a fun-filled breezy general quiz set from numismatics to sports to pop culture.
Re-live the Euphoria!!!
QM: Eiraiezhil R K,
BA Economics (2022-25),
The Quiz club of PSGCAS
Rose Cultivation Practices by Kushal Lamichhane.pdfkushallamichhame
This includes the overall cultivation practices of Rose prepared by:
Kushal Lamichhane (AKL)
Instructor
Shree Gandhi Adarsha Secondary School
Kageshowri Manohara-09, Kathmandu, Nepal
How to Manage Maintenance Request in Odoo 18Celine George
Efficient maintenance management is crucial for keeping equipment and work centers running smoothly in any business. Odoo 18 provides a Maintenance module that helps track, schedule, and manage maintenance requests efficiently.
This presentation has been made keeping in mind the students of undergraduate and postgraduate level. To keep the facts in a natural form and to display the material in more detail, the help of various books, websites and online medium has been taken. Whatever medium the material or facts have been taken from, an attempt has been made by the presenter to give their reference at the end.
In the seventh century, the rule of Sindh state was in the hands of Rai dynasty. We know the names of five kings of this dynasty- Rai Divji, Rai Singhras, Rai Sahasi, Rai Sihras II and Rai Sahasi II. During the time of Rai Sihras II, Nimruz of Persia attacked Sindh and killed him. After the return of the Persians, Rai Sahasi II became the king. After killing him, one of his Brahmin ministers named Chach took over the throne. He married the widow of Rai Sahasi and became the ruler of entire Sindh by suppressing the rebellions of the governors.
How to Manage Upselling of Subscriptions in Odoo 18Celine George
Subscriptions in Odoo 18 are designed to auto-renew indefinitely, ensuring continuous service for customers. However, businesses often need flexibility to adjust pricing or quantities based on evolving customer needs.
Analysis of Quantitative Data Parametric and non-parametric tests.pptxShrutidhara2
This presentation covers the following points--
Parametric Tests
• Testing the Significance of the Difference between Means
• Analysis of Variance (ANOVA) - One way and Two way
• Analysis of Co-variance (One-way)
Non-Parametric Tests:
• Chi-Square test
• Sign test
• Median test
• Sum of Rank test
• Mann-Whitney U-test
Moreover, it includes a comparison of parametric and non-parametric tests, a comparison of one-way ANOVA, two-way ANOVA, and one-way ANCOVA.
This presentation was provided by Nicole 'Nici" Pfeiffer of the Center for Open Science (COS), during the first session of our 2025 NISO training series "Secrets to Changing Behavior in Scholarly Communications." Session One was held June 5, 2025.
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxArshad Shaikh
Diptera, commonly known as flies, is a large and diverse order of insects that includes mosquitoes, midges, gnats, and horseflies. Characterized by a single pair of wings (hindwings are modified into balancing organs called halteres), Diptera are found in almost every environment and play important roles in ecosystems as pollinators, decomposers, and food sources. Some species, however, are significant pests and disease vectors, transmitting diseases like malaria, dengue, and Zika virus.
Different pricelists for different shops in odoo Point of Sale in Odoo 17Celine George
Price lists are a useful tool for managing the costs of your goods and services. This can assist you in working with other businesses effectively and maximizing your revenues. Additionally, you can provide your customers discounts by using price lists.
2. The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates
a Document Object Model of the page.
The HTML DOM model is constructed as a tree
of Objects:
2
4. With the object model, JavaScript gets all the power it
needs to create dynamic HTML:
JavaScript can change all the HTML elements in the page
JavaScript can change all the HTML attributes in the page
JavaScript can change all the CSS styles in the page
JavaScript can remove existing HTML elements and
attributes
JavaScript can add new HTML elements and attributes
JavaScript can react to all existing HTML events in the page
JavaScript can create new HTML events in the page
4
5. What is the DOM
The DOM is a W3C (World Wide Web Consortium)
standard. The DOM defines a standard for accessing
documents:
"The W3C Document Object Model (DOM) is a
platform and language-neutral interface that allows
programs and scripts to dynamically access and update
the content, structure, and style of a document."
5
6. The W3C DOM standard is separated into 3 different
parts:
Core DOM - standard model for all document types
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
6
7. What is the HTML DOM?
The HTML DOM is a standard object model
and programming interface for HTML. It defines:
The HTML elements as objects
The properties of all HTML elements
The methods to access all HTML elements
The events for all HTML elements
7
8. The DOM Programming Interface
The HTML DOM can be accessed with JavaScript (and
with other programming languages).
In the DOM, all HTML elements are defined as
objects.
The programming interface is the properties and
methods of each object.
A property is a value that you can get or set (like
changing the content of an HTML element).
A method is an action you can do (like add or deleting
an HTML element).
8
9. HTML DOM Nodes: In the HTML DOM (Document
Object Model), everything is a node:
The document itself is a document node
All HTML elements are element nodes
All HTML attributes are attribute nodes
Text inside HTML elements are text nodes
Comments are comment nodes
9
10. Node Relationships: The nodes in the node tree
have a hierarchical relationship to each other.
The terms parent, child, and sibling are used to
describe the relationships.
In a node tree, the top node is called the root (or root
node)
Every node has exactly one parent, except the root
(which has no parent)
A node can have a number of children
Siblings (brothers or sisters) are nodes with the same
parent
10
13. What is an Event ?
JavaScript's interaction with HTML is handled through events
that occur when the user or the browser manipulates a page.
When the page loads, it is called an event. When the user clicks a
button, that click too is an event. Other examples include events
like pressing any key, closing a window, resizing a window, etc.
Developers can use these events to execute JavaScript coded
responses, which cause buttons to close windows, messages to be
displayed to users, data to be validated, and virtually any other
type of response imaginable.
Events are a part of the Document Object Model (DOM) Level 3
and every HTML element contains a set of events which can
trigger JavaScript Code.
13
14. JavaScript 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.
14
15. examples
1) onclick events: This is a mouse event and provokes
any logic defined if the user clicks on the element it is
bound to.
2) onkeyup event: This event is a keyboard event and
executes instructions whenever a key is released after
pressing.
3) onmouseover event: This event corresponds to
hovering the mouse pointer over the element and its
children, to which it is bound to.
15
16. examples
onmouseout event: Whenever the mouse cursor
leaves the element which handles a mouseout event, a
function associated with it is executed.
onload event: When an element is loaded completely,
this event is evoked.
onfocus event: An element listing to this event
executes instructions whenever it recieves focus.
onblur event: This event is evoked when an element
loses focus.
16
17. JavaScript addEventListener()
The addEventListener() method is used to attach an event handler to a
particular element. It does not override the existing event handlers. Events are
said to be an essential part of the JavaScript. A web page responds according to
the event that occurred. Events can be user-generated or generated by API's. An
event listener is a JavaScript's procedure that waits for the occurrence of an
event.
The addEventListener() method is an inbuilt function of JavaScript. We can
add multiple event handlers to a particular element without overwriting the
existing event handlers.
Syntax
element1.addEventListener(click, function1);
element1.addEventListener(click, function2);
element1.addEventListener(mouseover, function3);
Although it has three parameters, the parameters event and function are
widely used. The third parameter is optional to define. The values of this
function are defined as follows.
17
18. Parameter Values
event: It is a required parameter. It can be defined as a string
that specifies the event's name.
Note: Do not use any prefix such as "on" with the parameter
value. For example, Use "click" instead of using "onclick".
function: It is also a required parameter. It is a JavaScript
function which responds to the event occur.
useCapture: It is an optional parameter. It is a Boolean type
value that specifies whether the event is executed in the
bubbling or capturing phase. Its possible values
are true and false. When it is set to true, the event handler
executes in the capturing phase. When it is set to false, the
handler executes in the bubbling phase. Its default value is false.
Let's see some of the illustrations of using the
addEventListener() method.
18
19. Event Bubbling or Event Capturing
Now, we understand the use of the third parameter of JavaScript's
addEventListener(), i.e., useCapture.
In HTML DOM, Bubbling and Capturing are the two ways of event
propagation. We can understand these ways by taking an example.
Suppose we have a div element and a paragraph element inside it, and we are
applying the "click" event to both of them using
the addEventListener() method. Now the question is on clicking the
paragraph element, which element's click event is handled first.
So, in Bubbling, the event of paragraph element is handled first, and then the
div element's event is handled. It means that in bubbling, the inner element's
event is handled first, and then the outermost element's event will be handled.
In Capturing the event of div element is handled first, and then the paragraph
element's event is handled. It means that in capturing the outer element's
event is handled first, and then the innermost element's event will be handled.
addEventListener(event, function, useCapture);
We can specify the propagation using the useCapture parameter. When it is
set to false (which is its default value), then the event uses bubbling
propagation, and when it is set to true, there is the capturing propagation.
19
20. Methods of document object
We can access and change the contents of document by its
methods.
The important methods of document object are as follows:
write("string")writes the given string on the
doucment.writeln("string")writes the given string on the
doucment with newline character at the
end.getElementById()returns the element having the given
id value.getElementsByName()returns all the elements
having the given name
value.getElementsByTagName()returns all the elements
having the given tag
name.getElementsByClassName()returns all the elements
having the given class name.
20
21. Accessing field value by document
object
In this example, we are going to get the value of input text
by user. Here, we are
using document.form1.name.value to get the value of
name field.
Here, document is the root element that represents the
html document.
form1 is the name of the form.
name is the attribute name of the input text.
value is the property, that returns the value of the input
text.
Let's see the simple example of document object that prints
name with welcome message.
21
22. example
<script type="text/javascript">
function printvalue(){
var name=document.form1.name.value;
alert("Welcome: "+name);
}
</script>
<form name="form1">
Enter Name:<input type="text" name="name"/>
<input type="button" onclick="printvalue()" value="print
name"/>
</form>
22
23. document.getElementById()
method
The document.getElementById() method returns
the element of specified id.
In the previous page, we have
used document.form1.name.value to get the value
of the input value. Instead of this, we can use
document.getElementById() method to get value of
the input text. But we need to define id for the input
field.
23
24. example
<script type="text/javascript">
function getcube(){
var number=document.getElementById("number").value;
alert(number*number*number);
}
</script>
<form>
Enter No:<input type="text" id="number" name="number"
/><br/>
<input type="button" value="cube" onclick="getcube()"/>
</form>
24
27. document.getElementsByTagName
() method
The document.getElementsByTagName() method
returns all the element of specified tag name.
The syntax of the getElementsByTagName() method is
given below:
27
28. example
<script type="text/javascript">
function countpara(){
var totalpara=document.getElementsByTagName("p");
alert("total p tags are: "+totalpara.length);
}
</script>
<p>This is a pragraph</p>
<p>Here we are going to count total number of paragraphs by ge
tElementByTagName() method.</p>
<p>Let's see the simple example</p>
<button onclick="countpara()">count paragraph</button>
28
29. example
<script type="text/javascript">
function counth2(){
var totalh2=document.getElementsByTagName("h2");
alert("total h2 tags are: "+totalh2.length);
}
function counth3(){
var totalh3=document.getElementsByTagName("h3");
alert("total h3 tags are: "+totalh3.length);
}
</script>
<h2>This is h2 tag</h2>
<h2>This is h2 tag</h2>
<h3>This is h3 tag</h3>
<h3>This is h3 tag</h3>
<h3>This is h3 tag</h3>
<button onclick="counth2()">count h2</button>
<button onclick="counth3()">count h3</button>
29
30. Form Validation
It is important to validate the form submitted by the
user because it can have inappropriate values. So,
validation is must to authenticate user.
JavaScript provides facility to validate the form on the
client-side so data processing will be faster than
server-side validation. Most of the web developers
prefer JavaScript form validation.
Through JavaScript, we can validate name, password,
email, date, mobile numbers and more fields.
30
31. example
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name==null || name==""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
}
</script>
<body>
<form name="myform" method="post" action="abc.jsp" onsubmit="return validateform()" >
Name: <input type="text" name="name"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="register">
</form>
31
32. DOM querySelector() Method
querySelector() method in HTML is used to return the first
element that matches a specified CSS selector(s) in the
document.
Note: The querySelector() method only returns first element
that match the specified selectors. To return all the matches, use
querySelectorAll() method.
Syntax:
element.querySelector(selectors)Selectors are the required field.
It Specifies one or more CSS selectors to match the element.
These selectors are used to select HTML elements based on their
id, classes, types, etc.
In case of multiple selectors, a comma is used to separate each
selector. The element which occurs first in the document is the
returned element.
32