SlideShare a Scribd company logo
JavaScript Ajax & DOM Manipulation Matthew Batchelder
Agenda JavaScript: What it is and isn't JavaScript: Uses What is the DOM? What is AJAX? jQuery FTW! Manipulating page elements (the DOM) in sweet ways Simplified AJAX Other Coolness Pluggability jQuery in myPlymouth
Before We Start! Important tools to have Use Firefox  Firebug JS Debugging FTW Web Developer Toolbar (handy) A sexy text editor (not notepad)
JS: What it is and isn’t NOT Java despite its name ECMAScript More than form validation Client-Side Scripting Language Dynamic Weakly Typed Object-Oriented (Prototype-Based) DOM Event Tool
JavaScript Sandbox Scripts run in a “sandbox” Can only perform web-related actions, not File-System actions Constrained by a “Same Origin Policy”
JS: Usage Drop this puppy in your page:  <html> <head> <title>Example JS Page</title> <script type=“text/javascript”> // javascript code goes here </script> </head> <body> … </body> </html>
JS: Literals The following are literals…each variable is literally the data assigned. <script type=“text/javascript”> var myNumber = 123; var myString = ‘Bork!’; var myBoolean = true; var myFunction = function(){ return ‘hello’;} var myRegExp = /bork/gi; var myArray = [1, 2, 3]; var myCarObject = { color: ‘red’, tires: 4, windows: 6 } </script>
JS: Objects Everything in JS is an Object Those literals can be written: <script type=“text/javascript”> var myNumber = new Number(123); var myString = new String(‘Bork!’); 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: Objects Objects values are accessed using dot (“.”) notation: example <html> <head> <title>Examples</title> <script type=&quot;text/javascript&quot;> var bork = 'Bork!'; var w00t = { hello: 'Greetings', yo: function(){ alert(bork + ' ' + this.hello); } }; var zomg = { nested: { iMeanReallyNested: { seriously: { out: function(){ alert('whee!'); } } } } }; w00t.yo(); zomg.nested.iMeanReallyNested.seriously.out(); </script> </head> <body> ... </body> </html>
JS: Control Structures if (bork) { //... }  else  { //... } while (bork) { //... } for (var i = 0; i< 10; i++) { //... } for (var element  in  array_of_elements) { //... } do  { //... }  while (bork); switch (bork) { case  1: // if bork == 1... case  'whee': // if bork == 'whee'... case  false: // if bork == false... default : // otherwise ... } try  { //... }  catch (err) { //... }
What is the DOM? DOM == Document Object Model The DOM is hierarchical <html> <head> <title>Example JS Page</title> </head> <body> <form id=“some_form”> <input type=“text” name=“bork”/> <input type=“submit” value=“Go”/> </form> </body> </html>
Finding DOM Elements document.getElementById() returns a specific element document.getElementByTag() returns an array of elements
DOM Element Attributes nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument 1 = an HTML element 2 = an element attribute 3 = text 8 = an HTML comment 9 = a document 10 = a document type definition DOM Attributes Node Types Here’s a  good article  that uses these.
Manipulating the DOM Dynamically creating and adding elements document.createElement appendChild example
innerHTML Why go through the trouble of creating Nodes? More efficient Easier example
Events Click Dblclick Mousedown Mouseup Mouseover Mousemove Mouseout Keypress Keydown Keyup Select Change Submit Reset Focus Blur Load Unload  Abort Error Resize Scroll Mouse Keyboard Frame/Object Form
Simple Alert Box <html> <head> <title>Example Message Box Page</title> <script type=“text/javascript”> alert(‘I like butter’); </script> </head> <body> … </body> </html>
Confirm Box Bound to an Event <html> <head> <title>Example Message Box Page</title> <script type=&quot;text/javascript&quot;> function doLoad() { document.getElementById('sweet-link').addEventListener(‘click’, confirmClick, false); }//end doLoad function confirmClick() { return confirm(‘Are you sure you wish to go to that link?’); }//end confirmClick window.addEventListener(‘load’, doLoad, false); </script> </head> <body> <a id=&quot;sweet-link&quot; href=&quot;http://borkweb.com&quot;>BorkWeb</a> </body> </html> example
Hiding/Displaying Elements Element visibility is a nice use of events and DOM manipulation example
AJAX AJAX (Asychronous Javascript and XML) Gives you the ability to load content dynamically! Loading content on demand Possible usability Issues Possible performance issues and benefits Limitation: the sandbox prevents Cross-Site Ajax
Ajax: XMLHttpRequest Loading content on demand: example
WAIT!!!!!!!!!!!!! Things can actually be a bit easier. How much?  Well most of the above.
WTF? jQuery.  That’s what we use on campus.  Its hawt.
What is jQuery? jQuery is a sweet JavaScript Library Its Mantra: Find stuff and do stuff with it Focuses on simplicity Get it  here Check out the  docs
Finding Elements Say goodbye to document.getElementById() and document.getElementByTag() Say hello to: $() Uses  CSS Selectors  to find elements and returns them as an array of elements.
Finding Elements With $ $(‘a’) $(‘.class’) $(‘#id’) $(‘.content div’) $(‘input[name=bork]’) $(‘input:first’) Here’s an  example . Check out the selector syntax for more info.
Lets do some of the stuff we already did… Adding Text Fields Toggling   Element Visibility Ajax Content
jQuery Coolness Browser data $.browser Effects Sliding Fading Animating Chaining $(‘a’).click(function(){alert(‘hello’);return false;}).css(‘font-weight’,’bold’).fadeOut(‘slow’);
jQuery Plugins Pluggable!  Additional jQuery functionality added by including  jQuery  plugins .
jQuery in myPlymouth Go Sidebar Bookmarks Tab Stack Etc… Check out the  source .
The End. Resources Slide Examples jQuery Image Sprites  (I talked about this briefly) Mega Man !

More Related Content

What's hot (20)

PPTX
Javascript
Nagarajan
 
PPT
Introduction to Javascript
Amit Tyagi
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PPTX
JSON: The Basics
Jeff Fox
 
PPT
Java Script ppt
Priya Goyal
 
PPTX
Introduction to Node js
Akshay Mathur
 
PPTX
jQuery
Jay Poojara
 
PDF
Bootstrap 5 basic
Jubair Ahmed Junjun
 
PPT
Js ppt
Rakhi Thota
 
PDF
A quick and fast intro to Kotlin
XPeppers
 
PDF
Node ppt
Tamil Selvan R S
 
PPT
JavaScript - An Introduction
Manvendra Singh
 
PPTX
HTTP request and response
Sahil Agarwal
 
PPTX
jQuery PPT
Dominic Arrojado
 
PDF
Php introduction
krishnapriya Tadepalli
 
PDF
JavaScript Programming
Sehwan Noh
 
PDF
Retrofit
Amin Cheloh
 
PPTX
Introduction to spring boot
Santosh Kumar Kar
 
PPTX
CSS
Akila Iroshan
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
Javascript
Nagarajan
 
Introduction to Javascript
Amit Tyagi
 
jQuery for beginners
Arulmurugan Rajaraman
 
JSON: The Basics
Jeff Fox
 
Java Script ppt
Priya Goyal
 
Introduction to Node js
Akshay Mathur
 
jQuery
Jay Poojara
 
Bootstrap 5 basic
Jubair Ahmed Junjun
 
Js ppt
Rakhi Thota
 
A quick and fast intro to Kotlin
XPeppers
 
JavaScript - An Introduction
Manvendra Singh
 
HTTP request and response
Sahil Agarwal
 
jQuery PPT
Dominic Arrojado
 
Php introduction
krishnapriya Tadepalli
 
JavaScript Programming
Sehwan Noh
 
Retrofit
Amin Cheloh
 
Introduction to spring boot
Santosh Kumar Kar
 
Lab #2: Introduction to Javascript
Walid Ashraf
 

Similar to JavaScript: Ajax & DOM Manipulation (20)

PPT
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
PPTX
jQuery
Vishwa Mohan
 
PPT
Javascript 2009
borkweb
 
PPT
J Query Public
pradeepsilamkoti
 
PPT
Intro to jQuery
Alan Hecht
 
PPTX
Jquery fundamentals
Salvatore Fazio
 
PPT
eXo SEA - JavaScript Introduction Training
Hoat Le
 
PPT
Don't Worry jQuery is very Easy:Learning Tips For jQuery
shabab shihan
 
PDF
22 j query1
Fajar Baskoro
 
PPT
Javascript Templating
bcruhl
 
PPTX
J query1
Manav Prasad
 
PPT
jQuery Fundamentals
Doncho Minkov
 
PPTX
JQuery_and_Ajax.pptx
AditiPawale1
 
PPT
J Query(04 12 2008) Foiaz
testingphase
 
PPTX
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
KEY
Week 4 - jQuery + Ajax
baygross
 
PPT
Introduction to Prototype JS Framework
Mohd Imran
 
PPTX
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
PPTX
Introduction to JQuery
Muhammad Afzal Qureshi
 
PPT
Think jQuery
Ying Zhang
 
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
jQuery
Vishwa Mohan
 
Javascript 2009
borkweb
 
J Query Public
pradeepsilamkoti
 
Intro to jQuery
Alan Hecht
 
Jquery fundamentals
Salvatore Fazio
 
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Don't Worry jQuery is very Easy:Learning Tips For jQuery
shabab shihan
 
22 j query1
Fajar Baskoro
 
Javascript Templating
bcruhl
 
J query1
Manav Prasad
 
jQuery Fundamentals
Doncho Minkov
 
JQuery_and_Ajax.pptx
AditiPawale1
 
J Query(04 12 2008) Foiaz
testingphase
 
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Week 4 - jQuery + Ajax
baygross
 
Introduction to Prototype JS Framework
Mohd Imran
 
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
Introduction to JQuery
Muhammad Afzal Qureshi
 
Think jQuery
Ying Zhang
 
Ad

Recently uploaded (20)

PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Digital Circuits, important subject in CS
contactparinay1
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Ad

JavaScript: Ajax & DOM Manipulation

  • 1. JavaScript Ajax & DOM Manipulation Matthew Batchelder
  • 2. Agenda JavaScript: What it is and isn't JavaScript: Uses What is the DOM? What is AJAX? jQuery FTW! Manipulating page elements (the DOM) in sweet ways Simplified AJAX Other Coolness Pluggability jQuery in myPlymouth
  • 3. Before We Start! Important tools to have Use Firefox Firebug JS Debugging FTW Web Developer Toolbar (handy) A sexy text editor (not notepad)
  • 4. JS: What it is and isn’t NOT Java despite its name ECMAScript More than form validation Client-Side Scripting Language Dynamic Weakly Typed Object-Oriented (Prototype-Based) DOM Event Tool
  • 5. JavaScript Sandbox Scripts run in a “sandbox” Can only perform web-related actions, not File-System actions Constrained by a “Same Origin Policy”
  • 6. JS: Usage Drop this puppy in your page: <html> <head> <title>Example JS Page</title> <script type=“text/javascript”> // javascript code goes here </script> </head> <body> … </body> </html>
  • 7. JS: Literals The following are literals…each variable is literally the data assigned. <script type=“text/javascript”> var myNumber = 123; var myString = ‘Bork!’; var myBoolean = true; var myFunction = function(){ return ‘hello’;} var myRegExp = /bork/gi; var myArray = [1, 2, 3]; var myCarObject = { color: ‘red’, tires: 4, windows: 6 } </script>
  • 8. JS: Objects Everything in JS is an Object Those literals can be written: <script type=“text/javascript”> var myNumber = new Number(123); var myString = new String(‘Bork!’); 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>
  • 9. JS: Objects Objects values are accessed using dot (“.”) notation: example <html> <head> <title>Examples</title> <script type=&quot;text/javascript&quot;> var bork = 'Bork!'; var w00t = { hello: 'Greetings', yo: function(){ alert(bork + ' ' + this.hello); } }; var zomg = { nested: { iMeanReallyNested: { seriously: { out: function(){ alert('whee!'); } } } } }; w00t.yo(); zomg.nested.iMeanReallyNested.seriously.out(); </script> </head> <body> ... </body> </html>
  • 10. JS: Control Structures if (bork) { //... } else { //... } while (bork) { //... } for (var i = 0; i< 10; i++) { //... } for (var element in array_of_elements) { //... } do { //... } while (bork); switch (bork) { case 1: // if bork == 1... case 'whee': // if bork == 'whee'... case false: // if bork == false... default : // otherwise ... } try { //... } catch (err) { //... }
  • 11. What is the DOM? DOM == Document Object Model The DOM is hierarchical <html> <head> <title>Example JS Page</title> </head> <body> <form id=“some_form”> <input type=“text” name=“bork”/> <input type=“submit” value=“Go”/> </form> </body> </html>
  • 12. Finding DOM Elements document.getElementById() returns a specific element document.getElementByTag() returns an array of elements
  • 13. DOM Element Attributes nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument 1 = an HTML element 2 = an element attribute 3 = text 8 = an HTML comment 9 = a document 10 = a document type definition DOM Attributes Node Types Here’s a good article that uses these.
  • 14. Manipulating the DOM Dynamically creating and adding elements document.createElement appendChild example
  • 15. innerHTML Why go through the trouble of creating Nodes? More efficient Easier example
  • 16. Events Click Dblclick Mousedown Mouseup Mouseover Mousemove Mouseout Keypress Keydown Keyup Select Change Submit Reset Focus Blur Load Unload Abort Error Resize Scroll Mouse Keyboard Frame/Object Form
  • 17. Simple Alert Box <html> <head> <title>Example Message Box Page</title> <script type=“text/javascript”> alert(‘I like butter’); </script> </head> <body> … </body> </html>
  • 18. Confirm Box Bound to an Event <html> <head> <title>Example Message Box Page</title> <script type=&quot;text/javascript&quot;> function doLoad() { document.getElementById('sweet-link').addEventListener(‘click’, confirmClick, false); }//end doLoad function confirmClick() { return confirm(‘Are you sure you wish to go to that link?’); }//end confirmClick window.addEventListener(‘load’, doLoad, false); </script> </head> <body> <a id=&quot;sweet-link&quot; href=&quot;http://borkweb.com&quot;>BorkWeb</a> </body> </html> example
  • 19. Hiding/Displaying Elements Element visibility is a nice use of events and DOM manipulation example
  • 20. AJAX AJAX (Asychronous Javascript and XML) Gives you the ability to load content dynamically! Loading content on demand Possible usability Issues Possible performance issues and benefits Limitation: the sandbox prevents Cross-Site Ajax
  • 21. Ajax: XMLHttpRequest Loading content on demand: example
  • 22. WAIT!!!!!!!!!!!!! Things can actually be a bit easier. How much? Well most of the above.
  • 23. WTF? jQuery. That’s what we use on campus. Its hawt.
  • 24. What is jQuery? jQuery is a sweet JavaScript Library Its Mantra: Find stuff and do stuff with it Focuses on simplicity Get it here Check out the docs
  • 25. Finding Elements Say goodbye to document.getElementById() and document.getElementByTag() Say hello to: $() Uses CSS Selectors to find elements and returns them as an array of elements.
  • 26. Finding Elements With $ $(‘a’) $(‘.class’) $(‘#id’) $(‘.content div’) $(‘input[name=bork]’) $(‘input:first’) Here’s an example . Check out the selector syntax for more info.
  • 27. Lets do some of the stuff we already did… Adding Text Fields Toggling Element Visibility Ajax Content
  • 28. jQuery Coolness Browser data $.browser Effects Sliding Fading Animating Chaining $(‘a’).click(function(){alert(‘hello’);return false;}).css(‘font-weight’,’bold’).fadeOut(‘slow’);
  • 29. jQuery Plugins Pluggable! Additional jQuery functionality added by including jQuery plugins .
  • 30. jQuery in myPlymouth Go Sidebar Bookmarks Tab Stack Etc… Check out the source .
  • 31. The End. Resources Slide Examples jQuery Image Sprites (I talked about this briefly) Mega Man !