JavaScript & Dom Manipulation

Mohammed Arif
Mohammed ArifManager, Interactive Development em SapientNitro
JavaScript & DOM Manipulation Mohammed Arif Senior Interactive Developer @  SapientNitro Twitter@ arif_iq Linkedin:  http:// in.linkedin.com/in/mohdarif Blog:  http:// www.mohammedarif.com
Agenda: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Before We Start! ,[object Object],[object Object],[object Object],[object Object]
JavaScript As “the Behavior Layer”: •  The behavior layer :   Is executed on the client and defines how different elements behave when the user interacts with them (JavaScript or ActionScript for Flash sites). •  The presentation layer :   Is displayed on the client and is the look of the web page (CSS, imagery).
[object Object],[object Object],[object Object]
JS: What it is and isn’t ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ECMAScript: ECMAScript is a scripting programming language, standardized by ECMA International in the ECMA-262 specification. The language is widely used on the web, and is often referred to as JavaScript or JScript. Each browser has its own implementation of the ECMAScript interface, which is then extended to contain the DOM and BOM. There are other languages that also implement and extend ECMAScript such as Windows Scripting Host (WSH), ActionScript in Macromedia Flash, and Nombas ScriptEase.
JS: Usage ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],However, noscript is deprecated in XHTML and strict} HTML, and there is no need for it—if you create JavaScript that is unobtrusive.
Naming conventions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JS: Literals ,[object Object],[object Object],<script type=“text/javascript”> var myNumber = 123; var myString = ‘Bork!’; var myBoolean = true; var myFunction = function(){ return ‘hello’;} //anonymous function   var myArray = [1, 2, 3]; </script>
Variables Scope ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JS: Objects ,[object Object],[object Object],<script type=“text/javascript”> var myNumber = new Number(123); var myString = new String(‘Rayyan’); var myBoolean = new Boolean(true); var myFunction = new Function(‘’, “return ‘hello’”);} var myRegExp = new RegExp(‘bork’); var myArray = new Array(); myArray[0] = 1; myArray[1] = 2; myArray[2] = 3; var myCarObject = new Object(); myCarObject.color = ‘red’; myCarObject.tires = 4; myCarObject.windows = 6; </script>
JS: Control Structures if (condition) { //... }  else  { //... } while (condition) { //... } for (var i = 0; i< 10; i++) { //... } for (var element  in  array_of_elements) { //... } do  { //... }  while (condition); switch (param) { case  1: // if param == 1... case  'whee': // if param == 'whee'... case  false: // if param == false... default : // otherwise ... } try  { //... }  catch (err) { //... }
What is the DOM? The  Document Object Model  (DOM) is an application programming interface (API) for HTML as well as XML. The DOM maps out an entire page as a document composed of a hierarchy of nodes.  It alter the appearance & content of a page without reloading the document. Each part of an HTML or XML page is a derivative of a node. Consider the following HTML page:
[object Object],[object Object],<html> <head> <title>Example JS Page</title> </head> <body> <div id=“Rayyan”> <ul>   <li>Delhi</li>   <li>Mumbai</li>   <li>Chennai</li>   <li>Kolkata</li> </ul> </div> </body> </html>
DOM Tree:
Finding DOM Elements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
DOM Element Attributes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],DOM Attributes Node Types (12)
Manipulating the DOM ,[object Object],[object Object],[object Object]
Events ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Mouse Keyboard Frame/Object Form
Event Handlers/Listeners: With an event handler you can do something with an element when an event occurs: when the user clicks an element, when the page loads, when a form is submitted, etc.  To assign an event handler in JavaScript, you have to get a reference to the object in question and then assign a function to the corresponding event handler property like this: var oDiv = document.getElementById(“div1”); oDiv.onclick = function () { alert(“I was clicked”); }; <div onclick=”alert(‘I was clicked’)”></div> &
Internet Explorer In IE, every element and window object has two methods: attachEvent()  and detachEvent(). var fnClick = function () { alert(“Clicked!”); }; var oDiv = document.getElementById(“div”); oDiv.attachEvent(“onclick”, fnClick); //add the event handler //do some other stuff here oDiv.detachEvent(“onclick”, fnClick); //remove the event handler
DOM (Mozilla, Opera, etc.) The DOM methods addEventListener() and removeEventListener() accomplish the assignment and removal of event handlers. These methods, unlike IE, take three parameters: the event name, the function to assign, and whether the handler should be used for the bubbling or capture phase. If the handler is to be used in the capture phase, the third parameter is true; for the bubbling phase, it is false. Here’s the general syntax: [Object]. addEventListener(“name_of_event”, fnHandler, bCapture); [Object]. removeEventListener(“name_of_event”, fnHandler, bCapture); ,[object Object]
References ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
1 de 24

Recomendados

Basics of JavaScript por
Basics of JavaScriptBasics of JavaScript
Basics of JavaScriptBala Narayanan
10.1K visualizações29 slides
JavaScript Programming por
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
14.9K visualizações81 slides
Javascript essentials por
Javascript essentialsJavascript essentials
Javascript essentialsBedis ElAchèche
1.5K visualizações54 slides
Introduction to Javascript por
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
13.5K visualizações46 slides
Lab #2: Introduction to Javascript por
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
2.9K visualizações41 slides
Dom(document object model) por
Dom(document object model)Dom(document object model)
Dom(document object model)Partnered Health
2.5K visualizações20 slides

Mais conteúdo relacionado

Mais procurados

Dom por
DomDom
DomRakshita Upadhyay
2K visualizações14 slides
Javascript basics por
Javascript basicsJavascript basics
Javascript basicsshreesenthil
1.7K visualizações32 slides
Javascript Basic por
Javascript BasicJavascript Basic
Javascript BasicKang-min Liu
1.8K visualizações36 slides
Javascript 101 por
Javascript 101Javascript 101
Javascript 101Shlomi Komemi
2.1K visualizações32 slides
JavaScript: Events Handling por
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events HandlingYuriy Bezgachnyuk
5.3K visualizações19 slides
JavaScript Basics por
JavaScript BasicsJavaScript Basics
JavaScript BasicsMats Bryntse
1.6K visualizações18 slides

Mais procurados(20)

Javascript basics por shreesenthil
Javascript basicsJavascript basics
Javascript basics
shreesenthil1.7K visualizações
Javascript Basic por Kang-min Liu
Javascript BasicJavascript Basic
Javascript Basic
Kang-min Liu1.8K visualizações
Javascript 101 por Shlomi Komemi
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi2.1K visualizações
JavaScript: Events Handling por Yuriy Bezgachnyuk
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
Yuriy Bezgachnyuk5.3K visualizações
JavaScript Basics por Mats Bryntse
JavaScript BasicsJavaScript Basics
JavaScript Basics
Mats Bryntse1.6K visualizações
Java script errors &amp; exceptions handling por AbhishekMondal42
Java script  errors &amp; exceptions handlingJava script  errors &amp; exceptions handling
Java script errors &amp; exceptions handling
AbhishekMondal42349 visualizações
JavaScript - Chapter 8 - Objects por WebStackAcademy
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy1.6K visualizações
Java script por Shyam Khant
Java scriptJava script
Java script
Shyam Khant2.7K visualizações
Javascript por guest03a6e6
JavascriptJavascript
Javascript
guest03a6e620K visualizações
Javascript por Nagarajan
JavascriptJavascript
Javascript
Nagarajan5.4K visualizações
JavaScript - Chapter 6 - Basic Functions por WebStackAcademy
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy1.1K visualizações
Java script por Sadeek Mohammed
Java scriptJava script
Java script
Sadeek Mohammed3.7K visualizações
Introduction to web programming with JavaScript por T11 Sessions
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
T11 Sessions1.4K visualizações
javascript objects por Vijay Kalyan
javascript objectsjavascript objects
javascript objects
Vijay Kalyan5.1K visualizações
javaScript.ppt por sentayehu
javaScript.pptjavaScript.ppt
javaScript.ppt
sentayehu534 visualizações
JavaScript - Chapter 9 - TypeConversion and Regular Expressions por WebStackAcademy
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy360 visualizações

Similar a JavaScript & Dom Manipulation

JS basics por
JS basicsJS basics
JS basicsMohd Saeed
650 visualizações36 slides
eXo SEA - JavaScript Introduction Training por
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
1.7K visualizações44 slides
Scripting The Dom por
Scripting The DomScripting The Dom
Scripting The DomAra Pehlivanian
1.3K visualizações53 slides
JavaScript with Syntax & Implementation por
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationSoumen Santra
309 visualizações33 slides
Basic Java script handouts for students por
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students shafiq sangi
1.8K visualizações77 slides
Javascript 2009 por
Javascript 2009Javascript 2009
Javascript 2009borkweb
4.7K visualizações38 slides

Similar a JavaScript & Dom Manipulation(20)

JS basics por Mohd Saeed
JS basicsJS basics
JS basics
Mohd Saeed650 visualizações
eXo SEA - JavaScript Introduction Training por Hoat Le
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le1.7K visualizações
Scripting The Dom por Ara Pehlivanian
Scripting The DomScripting The Dom
Scripting The Dom
Ara Pehlivanian1.3K visualizações
JavaScript with Syntax & Implementation por Soumen Santra
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
Soumen Santra309 visualizações
Basic Java script handouts for students por shafiq sangi
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students
shafiq sangi1.8K visualizações
Javascript 2009 por borkweb
Javascript 2009Javascript 2009
Javascript 2009
borkweb4.7K visualizações
Advisor Jumpstart: JavaScript por dominion
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScript
dominion1.2K visualizações
Basic JavaScript Tutorial por DHTMLExtreme
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme3.8K visualizações
Client side scripting using Javascript por Bansari Shah
Client side scripting using JavascriptClient side scripting using Javascript
Client side scripting using Javascript
Bansari Shah191 visualizações
Eugene Andruszczenko: jQuery por Refresh Events
Eugene Andruszczenko: jQueryEugene Andruszczenko: jQuery
Eugene Andruszczenko: jQuery
Refresh Events1K visualizações
jQuery Presentation - Refresh Events por Eugene Andruszczenko
jQuery Presentation - Refresh EventsjQuery Presentation - Refresh Events
jQuery Presentation - Refresh Events
Eugene Andruszczenko1.7K visualizações
Javascript: Ajax & DOM Manipulation v1.2 por borkweb
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
borkweb2.3K visualizações
Presentation por priyankazope
PresentationPresentation
Presentation
priyankazope188 visualizações
JavaScript por Doncho Minkov
JavaScriptJavaScript
JavaScript
Doncho Minkov2.4K visualizações
JAVA SCRIPT por Mohammed Hussein
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Mohammed Hussein2.9K visualizações
Introduction of javascript por syeda zoya mehdi
Introduction of javascriptIntroduction of javascript
Introduction of javascript
syeda zoya mehdi350 visualizações
Introduction to Javascript programming por Fulvio Corno
Introduction to Javascript programmingIntroduction to Javascript programming
Introduction to Javascript programming
Fulvio Corno4.9K visualizações
JavaScript: Ajax & DOM Manipulation por borkweb
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
borkweb8.9K visualizações
JAVA SCRIPT por Go4Guru
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Go4Guru2K visualizações
jQuery por Vishwa Mohan
jQueryjQuery
jQuery
Vishwa Mohan3.3K visualizações

Mais de Mohammed Arif

Yeoman por
YeomanYeoman
YeomanMohammed Arif
3.2K visualizações26 slides
Grunt - The JavaScript Task Runner por
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task RunnerMohammed Arif
6.3K visualizações20 slides
Thalassemia por
ThalassemiaThalassemia
ThalassemiaMohammed Arif
5.1K visualizações12 slides
MVC & backbone.js por
MVC & backbone.jsMVC & backbone.js
MVC & backbone.jsMohammed Arif
4K visualizações23 slides
HTML5 ★ Boilerplate por
HTML5 ★ BoilerplateHTML5 ★ Boilerplate
HTML5 ★ BoilerplateMohammed Arif
2K visualizações13 slides
jQuery por
jQueryjQuery
jQueryMohammed Arif
2.2K visualizações13 slides

Mais de Mohammed Arif(6)

Yeoman por Mohammed Arif
YeomanYeoman
Yeoman
Mohammed Arif3.2K visualizações
Grunt - The JavaScript Task Runner por Mohammed Arif
Grunt - The JavaScript Task RunnerGrunt - The JavaScript Task Runner
Grunt - The JavaScript Task Runner
Mohammed Arif6.3K visualizações
Thalassemia por Mohammed Arif
ThalassemiaThalassemia
Thalassemia
Mohammed Arif5.1K visualizações
MVC & backbone.js por Mohammed Arif
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
Mohammed Arif4K visualizações
HTML5 ★ Boilerplate por Mohammed Arif
HTML5 ★ BoilerplateHTML5 ★ Boilerplate
HTML5 ★ Boilerplate
Mohammed Arif2K visualizações
jQuery por Mohammed Arif
jQueryjQuery
jQuery
Mohammed Arif2.2K visualizações

Último

Transcript: The Details of Description Techniques tips and tangents on altern... por
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
136 visualizações15 slides
Democratising digital commerce in India-Report por
Democratising digital commerce in India-ReportDemocratising digital commerce in India-Report
Democratising digital commerce in India-ReportKapil Khandelwal (KK)
15 visualizações161 slides
Attacking IoT Devices from a Web Perspective - Linux Day por
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day Simone Onofri
16 visualizações68 slides
Case Study Copenhagen Energy and Business Central.pdf por
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdfAitana
16 visualizações3 slides
Piloting & Scaling Successfully With Microsoft Viva por
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft VivaRichard Harbridge
12 visualizações160 slides
STPI OctaNE CoE Brochure.pdf por
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
14 visualizações1 slide

Último(20)

Transcript: The Details of Description Techniques tips and tangents on altern... por BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada136 visualizações
Democratising digital commerce in India-Report por Kapil Khandelwal (KK)
Democratising digital commerce in India-ReportDemocratising digital commerce in India-Report
Democratising digital commerce in India-Report
Kapil Khandelwal (KK)15 visualizações
Attacking IoT Devices from a Web Perspective - Linux Day por Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri16 visualizações
Case Study Copenhagen Energy and Business Central.pdf por Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 visualizações
Piloting & Scaling Successfully With Microsoft Viva por Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Richard Harbridge12 visualizações
STPI OctaNE CoE Brochure.pdf por madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 visualizações
Five Things You SHOULD Know About Postman por Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 visualizações
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... por Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 visualizações
Mini-Track: Challenges to Network Automation Adoption por Network Automation Forum
Mini-Track: Challenges to Network Automation AdoptionMini-Track: Challenges to Network Automation Adoption
Mini-Track: Challenges to Network Automation Adoption
Network Automation Forum12 visualizações
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... por Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Jasper Oosterveld18 visualizações
Voice Logger - Telephony Integration Solution at Aegis por Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 visualizações
virtual reality.pptx por G036GaikwadSnehal
virtual reality.pptxvirtual reality.pptx
virtual reality.pptx
G036GaikwadSnehal11 visualizações
HTTP headers that make your website go faster - devs.gent November 2023 por Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 visualizações
Data Integrity for Banking and Financial Services por Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely21 visualizações
Microsoft Power Platform.pptx por Uni Systems S.M.S.A.
Microsoft Power Platform.pptxMicrosoft Power Platform.pptx
Microsoft Power Platform.pptx
Uni Systems S.M.S.A.53 visualizações
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive por Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Network Automation Forum31 visualizações
Igniting Next Level Productivity with AI-Infused Data Integration Workflows por Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software263 visualizações
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors por sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 visualizações

JavaScript & Dom Manipulation

  • 1. JavaScript & DOM Manipulation Mohammed Arif Senior Interactive Developer @ SapientNitro Twitter@ arif_iq Linkedin: http:// in.linkedin.com/in/mohdarif Blog: http:// www.mohammedarif.com
  • 2.
  • 3.
  • 4. JavaScript As “the Behavior Layer”: • The behavior layer : Is executed on the client and defines how different elements behave when the user interacts with them (JavaScript or ActionScript for Flash sites). • The presentation layer : Is displayed on the client and is the look of the web page (CSS, imagery).
  • 5.
  • 6.
  • 7. ECMAScript: ECMAScript is a scripting programming language, standardized by ECMA International in the ECMA-262 specification. The language is widely used on the web, and is often referred to as JavaScript or JScript. Each browser has its own implementation of the ECMAScript interface, which is then extended to contain the DOM and BOM. There are other languages that also implement and extend ECMAScript such as Windows Scripting Host (WSH), ActionScript in Macromedia Flash, and Nombas ScriptEase.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. JS: Control Structures if (condition) { //... } else { //... } while (condition) { //... } for (var i = 0; i< 10; i++) { //... } for (var element in array_of_elements) { //... } do { //... } while (condition); switch (param) { case 1: // if param == 1... case 'whee': // if param == 'whee'... case false: // if param == false... default : // otherwise ... } try { //... } catch (err) { //... }
  • 14. What is the DOM? The Document Object Model (DOM) is an application programming interface (API) for HTML as well as XML. The DOM maps out an entire page as a document composed of a hierarchy of nodes. It alter the appearance & content of a page without reloading the document. Each part of an HTML or XML page is a derivative of a node. Consider the following HTML page:
  • 15.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Event Handlers/Listeners: With an event handler you can do something with an element when an event occurs: when the user clicks an element, when the page loads, when a form is submitted, etc. To assign an event handler in JavaScript, you have to get a reference to the object in question and then assign a function to the corresponding event handler property like this: var oDiv = document.getElementById(“div1”); oDiv.onclick = function () { alert(“I was clicked”); }; <div onclick=”alert(‘I was clicked’)”></div> &
  • 22. Internet Explorer In IE, every element and window object has two methods: attachEvent() and detachEvent(). var fnClick = function () { alert(“Clicked!”); }; var oDiv = document.getElementById(“div”); oDiv.attachEvent(“onclick”, fnClick); //add the event handler //do some other stuff here oDiv.detachEvent(“onclick”, fnClick); //remove the event handler
  • 23.
  • 24.