SlideShare a Scribd company logo
UNIT-II
JAVA SCRIPT
JavaScript Objects
• A javaScript object is an entity having state
and behavior (properties and method). For
example: car, pen, bike, chair, glass, keyboard,
monitor etc.
• JavaScript is an object-based language.
Everything is an object in JavaScript.
• JavaScript is template based not class based.
Here, we don't create class to get the object.
But, we direct create objects.
Creating Objects in JavaScript
There are 3 ways to create objects.By object
literal
• By creating instance of Object directly (using
new keyword)
• By using an object constructor (using new
keyword)
1) JavaScript Object by object literal
• The syntax of creating object using object
literal is given below:
• object={property1:value1,property2:value2.....
propertyN:valueN}
EXAMPLE
<script>
emp={id:102,name:"Shyam Kumar",salary:40000
}
document.write(emp.id+" "+emp.name+" "+emp
.salary);
</script>
Output of the above example
102 Shyam Kumar 40000
2) By creating instance of Object
• The syntax of creating object directly is given
below:
• var objectname=new Object();
• Here, new keyword is used to create object.
EXAMPLE
<script>
var emp=new Object();
emp.id=101;
emp.name="Ravi Malik";
emp.salary=50000;
document.write(emp.id+" "+emp.name+" "+emp.sa
lary);
</script>
• Output of the above example
• 101 Ravi 50000
3) By using an Object constructor
• Here, you need to create function with
arguments. Each argument value can be
assigned in the current object by using this
keyword.
• The this keyword refers to the current object.
EXAMPLE
<script>
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
}
e=new emp(103,"Vimal Jaiswal",30000);
document.write(e.id+" "+e.name+" "+e.salary);
</script>
• Output of the above example
• 103 Vimal Jaiswal 30000
Document Object Model
• The document object represents the whole
html document.
• When html document is loaded in the
browser, it becomes a document object.
• It is the root element that represents the html
document.
• It has properties and methods.
• By the help of document object, we can add
dynamic content to our web page.
Properties of document object
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.
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 n
ame"/>
• </form>
• Section 1. Getting started
• Understanding the Document Object Model in
JavaScript
• Section 2. Selecting elements
• getElementById() – select an element by id.
• getElementsByName() – select elements by name.
• getElementsByTagName() – select elements by a tag
name.
• getElementsByClassName() – select elements by one or
more class names.
• querySelector() – select elements by CSS selectors.
• Section 3. Traversing elements
• Get the parent element – get the parent node
of an element.
• Get child elements – get children of an
element.
• Get siblings of an element – get siblings of an
element.
Section 4. Manipulating elements
• createElement() – create a new element.
• appendChild() – append a node to a list of child nodes of a
specified parent node.
• textContent – get and set the text content of a node.
• innerHTML – get and set the HTML content of an element.
• innerHTML vs. createElement – explain the differences
beetween innerHTML and createElement when it comes to
creating new elements.
• DocumentFragment – learn how to compose DOM nodes
and insert them into the active DOM tree.
• insertBefore() – insert a new node before an existing node
as a child node of a specified parent node.
Section 5. Working with Attributes
• HTML Attributes & DOM Object’s Properties –
understand the relationship between HTML
attributes & DOM object’s properties.
• setAttribute() – set the value of a specified
attribute on a element.
• getAttribute() – get the value of an attribute on
an element.
• removeAttribute() – remove an attribute from a
specified element.
• hasAttribute() – check if an element has a
specified attribute or not.
Section 6. Manipulating Element’s
Styles
• style property – get or set inline styles of an
element.
• getComputedStyle() – return the computed style
of an element.
• className property – return a list of space-
separated CSS classes.
• classList property – manipulate CSS classes of an
element.
• Element’s width & height – get the width and
height of an element.
Html in Dreamweaver, and view the
Source Code in Split view.
• Download and save the project files.
• Define the alert function.
• Define the event.
• Test your JavaScript in a browser.
• Access the jQuery widgets.
• Open the second practice file.
• Add a jQuery function.
• Use <script> tags
Inserting JavaScript
• Dreamweaver includes many fun and useful
interactive effects—Spry menus, Spry form
validation, Spry effects, Dreamweaver behaviors,
and so on.
• JavaScript is the “engine” behind all of them. Of
course, you can do a lot of other cool things with
JavaScript that Dreamweaver hasn’t
programmed.
• In these cases, you need to wade into the depths
of JavaScript programming yourself.
• The most straightforward approach, especially
if you’re familiar with JavaScript, is to simply
switch into Code view (Ctrl+` [Option-`]), and
then code away.
• If you prefer, you can use Dreamweaver’s
Script window to add JavaScript code
ppt- u 2.pptx

More Related Content

Similar to ppt- u 2.pptx

6867389.ppt
6867389.ppt6867389.ppt
6867389.ppt
SunilChaluvaiah
 
6867389 (1).ppt
6867389 (1).ppt6867389 (1).ppt
6867389 (1).ppt
SunilChaluvaiah
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptzand3rs
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
NuurAxmed2
 
Jquery
JqueryJquery
Jquery
Zoya Shaikh
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
WebStackAcademy
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handling
smitha273566
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
prince Loffar
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
Jennifer Estrada
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
Terry Yoast
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
Fu Cheng
 
Web Technology Part 3
Web Technology Part 3Web Technology Part 3
Web Technology Part 3
Thapar Institute
 
IPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptxIPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptx
DhavalaShreeBJain
 
UNIT 1 (7).pptx
UNIT 1 (7).pptxUNIT 1 (7).pptx
UNIT 1 (7).pptx
DrDhivyaaCRAssistant
 
SPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsSPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsMark Rackley
 
OOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptxOOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptx
uzairrrfr
 

Similar to ppt- u 2.pptx (20)

6867389.ppt
6867389.ppt6867389.ppt
6867389.ppt
 
6867389 (1).ppt
6867389 (1).ppt6867389 (1).ppt
6867389 (1).ppt
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
Jquery
JqueryJquery
Jquery
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
 
Dom date and objects and event handling
Dom date and objects and event handlingDom date and objects and event handling
Dom date and objects and event handling
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
Web Technology Part 3
Web Technology Part 3Web Technology Part 3
Web Technology Part 3
 
IPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptxIPP-M5-C1-Classes _ Objects python -S2.pptx
IPP-M5-C1-Classes _ Objects python -S2.pptx
 
UNIT 1 (7).pptx
UNIT 1 (7).pptxUNIT 1 (7).pptx
UNIT 1 (7).pptx
 
SPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsSPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentials
 
Extjs
ExtjsExtjs
Extjs
 
OOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptxOOP02-27022023-090456am.pptx
OOP02-27022023-090456am.pptx
 
Java scriptforjavadev part2a
Java scriptforjavadev part2aJava scriptforjavadev part2a
Java scriptforjavadev part2a
 

Recently uploaded

The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 

Recently uploaded (20)

The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 

ppt- u 2.pptx

  • 2. JavaScript Objects • A javaScript object is an entity having state and behavior (properties and method). For example: car, pen, bike, chair, glass, keyboard, monitor etc. • JavaScript is an object-based language. Everything is an object in JavaScript. • JavaScript is template based not class based. Here, we don't create class to get the object. But, we direct create objects.
  • 3. Creating Objects in JavaScript There are 3 ways to create objects.By object literal • By creating instance of Object directly (using new keyword) • By using an object constructor (using new keyword)
  • 4. 1) JavaScript Object by object literal • The syntax of creating object using object literal is given below: • object={property1:value1,property2:value2..... propertyN:valueN}
  • 5. EXAMPLE <script> emp={id:102,name:"Shyam Kumar",salary:40000 } document.write(emp.id+" "+emp.name+" "+emp .salary); </script> Output of the above example 102 Shyam Kumar 40000
  • 6. 2) By creating instance of Object • The syntax of creating object directly is given below: • var objectname=new Object(); • Here, new keyword is used to create object.
  • 7. EXAMPLE <script> var emp=new Object(); emp.id=101; emp.name="Ravi Malik"; emp.salary=50000; document.write(emp.id+" "+emp.name+" "+emp.sa lary); </script> • Output of the above example • 101 Ravi 50000
  • 8. 3) By using an Object constructor • Here, you need to create function with arguments. Each argument value can be assigned in the current object by using this keyword. • The this keyword refers to the current object.
  • 9. EXAMPLE <script> function emp(id,name,salary){ this.id=id; this.name=name; this.salary=salary; } e=new emp(103,"Vimal Jaiswal",30000); document.write(e.id+" "+e.name+" "+e.salary); </script> • Output of the above example • 103 Vimal Jaiswal 30000
  • 10. Document Object Model • The document object represents the whole html document. • When html document is loaded in the browser, it becomes a document object. • It is the root element that represents the html document. • It has properties and methods. • By the help of document object, we can add dynamic content to our web page.
  • 12. 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.
  • 13. 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 n ame"/> • </form>
  • 14. • Section 1. Getting started • Understanding the Document Object Model in JavaScript • Section 2. Selecting elements • getElementById() – select an element by id. • getElementsByName() – select elements by name. • getElementsByTagName() – select elements by a tag name. • getElementsByClassName() – select elements by one or more class names. • querySelector() – select elements by CSS selectors.
  • 15. • Section 3. Traversing elements • Get the parent element – get the parent node of an element. • Get child elements – get children of an element. • Get siblings of an element – get siblings of an element.
  • 16. Section 4. Manipulating elements • createElement() – create a new element. • appendChild() – append a node to a list of child nodes of a specified parent node. • textContent – get and set the text content of a node. • innerHTML – get and set the HTML content of an element. • innerHTML vs. createElement – explain the differences beetween innerHTML and createElement when it comes to creating new elements. • DocumentFragment – learn how to compose DOM nodes and insert them into the active DOM tree. • insertBefore() – insert a new node before an existing node as a child node of a specified parent node.
  • 17. Section 5. Working with Attributes • HTML Attributes & DOM Object’s Properties – understand the relationship between HTML attributes & DOM object’s properties. • setAttribute() – set the value of a specified attribute on a element. • getAttribute() – get the value of an attribute on an element. • removeAttribute() – remove an attribute from a specified element. • hasAttribute() – check if an element has a specified attribute or not.
  • 18. Section 6. Manipulating Element’s Styles • style property – get or set inline styles of an element. • getComputedStyle() – return the computed style of an element. • className property – return a list of space- separated CSS classes. • classList property – manipulate CSS classes of an element. • Element’s width & height – get the width and height of an element.
  • 19. Html in Dreamweaver, and view the Source Code in Split view. • Download and save the project files. • Define the alert function. • Define the event. • Test your JavaScript in a browser. • Access the jQuery widgets. • Open the second practice file. • Add a jQuery function. • Use <script> tags
  • 20. Inserting JavaScript • Dreamweaver includes many fun and useful interactive effects—Spry menus, Spry form validation, Spry effects, Dreamweaver behaviors, and so on. • JavaScript is the “engine” behind all of them. Of course, you can do a lot of other cool things with JavaScript that Dreamweaver hasn’t programmed. • In these cases, you need to wade into the depths of JavaScript programming yourself.
  • 21. • The most straightforward approach, especially if you’re familiar with JavaScript, is to simply switch into Code view (Ctrl+` [Option-`]), and then code away. • If you prefer, you can use Dreamweaver’s Script window to add JavaScript code