SlideShare a Scribd company logo
1 of 22
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

JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - ObjectsWebStackAcademy
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptzand3rs
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
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 handlingsmitha273566
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy stepsprince Loffar
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05Terry 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 dojoFu Cheng
 
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.pptxuzairrrfr
 
Prototype Object.pptx
Prototype Object.pptxPrototype Object.pptx
Prototype Object.pptxSteins18
 

Similar to ppt- u 2.pptx (20)

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
 
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
 
Prototype Object.pptx
Prototype Object.pptxPrototype Object.pptx
Prototype Object.pptx
 
About Python
About PythonAbout Python
About Python
 

Recently uploaded

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

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