SlideShare a Scribd company logo
Document	
  Object	
  Model	
  and	
  
JavaScript	
  
Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
W3C	
  DOM	
  
•  DOM	
  –	
  Document	
  Object	
  Model	
  –	
  cross-­‐
plaDorm	
  and	
  language-­‐independent	
  
convenFon	
  for	
  interacFng	
  with	
  objects	
  in	
  
HTML	
  and	
  in	
  XML.	
  
•  With	
  DOM	
  you	
  can	
  manipulate	
  html/xml	
  
document!	
  Dynamic	
  html!	
  
•  Public	
  interface	
  available:	
  hPp://www.w3.org/
DOM/DOMTR	
  	
  
W3C	
  DOM	
  Levels	
  
•  (	
  DOM	
  Level	
  0	
  and	
  Intermediate	
  DOM	
  )	
  
–  Not	
  W3C	
  Standards,	
  used	
  in	
  Netscape	
  2	
  (Level	
  0)	
  and	
  
Netscape	
  4	
  (Intermediate	
  DOM)	
  	
  
•  DOM	
  Level	
  1	
  
–  1998:	
  Ability	
  to	
  change	
  enFre	
  HTML	
  or	
  XML	
  document	
  
•  DOM	
  Level	
  2	
  
–  2001:	
  Introduces	
  “getElementById”	
  funcFon,	
  event	
  
model	
  and	
  support	
  for	
  XML	
  namespaces	
  
•  DOM	
  Level	
  3	
  
–  2004:	
  XPath,	
  keyboard	
  event	
  handling	
  
Reality	
  
See	
  
hPp://www.quirksmode.org/dom/w3c_core.html	
  
DOM	
  Programming	
  Intro	
  
•  DOM	
  is	
  a	
  model	
  that	
  describes	
  how	
  all	
  
elements	
  in	
  an	
  html	
  page	
  are	
  related	
  to	
  
topmost	
  structure:	
  document	
  itself	
  
•  Can	
  influence	
  the	
  document	
  
– See:	
  hPp://www.w3.org/TR/REC-­‐DOM-­‐Level-­‐1/
introducFon.html	
  
•  Possible	
  to	
  read,	
  modify	
  and	
  delete	
  tags	
  
Node	
  
•  In	
  DOM,	
  each	
  object	
  is	
  Node	
  
•  In	
  this	
  
– <p>Hello</p>	
  
•  You	
  have	
  two	
  nodes	
  	
  
– 1)	
  element	
  node	
  -­‐	
  p	
  	
  
– 2)	
  text	
  node	
  -­‐	
  "Hello"	
  
•  Text	
  node	
  is	
  child	
  node	
  of	
  p	
  element.	
  P	
  
element	
  is	
  parent	
  node	
  of	
  the	
  text	
  node	
  
Node	
  Example	
  
<p>This is a <strong>paragraph</strong></p>
<p>
|
--------------
| |
This is a <strong>
|
|
paragraph
APribute	
  Node	
  
<a href=“http://www.tamk.fi”>TAMK</a>
<a> -----------------
| |
TAMK href
|
http://www.tamk.fi
Different	
  Nodes	
  
•  Element	
  node:	
  p,	
  img,	
  a	
  
•  Text	
  node:	
  sometext	
  
•  APribute	
  node:	
  src	
  
DOM	
  Level	
  1:	
  To	
  Access	
  DOM	
  tree	
  
•  X	
  can	
  be	
  some	
  node	
  
– var parent = x.parentNode;
– var firstchild = x.childNodes[0];
•  How	
  to	
  get	
  reference	
  to	
  x?	
  
Document	
  object	
  
Access	
  
var title =
document.firstChild.firstChild.lastChild;
// document.html.head.title
var title =
document.firstChild.childNodes[0].childNodes[
0];
Gelng	
  Element	
  Easier	
  Way	
  
var x =
document.getElementsByTagName(‘strong')[0]
var x = document.getElementById('hereweare');
	
  
Changing	
  the	
  Node	
  
// <a href=“” id=“someId”>Link</p>
var x =
document.getElementById(’someId');
x.firstChild.nodeValue = “Hello!”;
x.setAttribute(“href”, “http:/…”);
	
  
Inner	
  HTML	
  
// <a href=“” id=“someId”>Link</p>
var x = document.getElementById(’someId');
x.innerHTML = “Hello!”;
// innerHTML is NOT W3C Standard and it’s
// slower…
CreaFng	
  and	
  Removing	
  Nodes	
  
var x = document.createElement(’hr');
document.getElementById('inserthrhere').appendChild(x);
var node = document.getElementById('inserthrhere')
node.removeChild(node.childNodes[0]);
var x = document.createTextNode(’SomeText');
document.getElementById('hereweare').appendChild(x);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function change()
{
// Get list of ALL <h1> - elements
var listOfHeading1 = window.document.getElementsByTagName("h1");
// Find the first <h1> - element in the list
var heading1 = listOfHeading1[0];
// Get the child - element of the first <h1> - element (Text)
var text = heading1.firstChild;
// Replace the text
text.data = "Hello from JS!";
}
//]]>
</script>
</head>
<body>
<h1>Title</h1>
<input type="submit" onClick="change();" value="click!"/>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function change()
{
// Reference to the table - element
var table = document.getElementById("mytable");
var tr = document.createElement("tr"); // <tr>
var td1 = document.createElement("td"); // <td>
var td1Text = document.createTextNode("New Cell"); // "New Cell"
td1.appendChild(td1Text); // <td>New Cell</td>
var td2 = document.createElement("td"); // <td>
var td2Text = document.createTextNode("New Cell"); // "New Cell"
td2.appendChild(td2Text); // <td>New Cell</td>
tr.appendChild(td1);
tr.appendChild(td2);
table.appendChild(tr);
}
//]]>
</script>
</head>
<body>
<table id="mytable" border="1">
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
</table>
<input type="submit" onClick="change();" value="Add Row"/>
</body>
</html>

More Related Content

What's hot (20)

PPTX
Introduction to the DOM
tharaa abu ashour
 
PPTX
INTRODUCTION TO DOM AND DOM TREE
systematiclab
 
PPTX
Document Object Model (DOM)
GOPAL BASAK
 
PPTX
Document object model(dom)
rahul kundu
 
PPT
Document Object Model
chomas kandar
 
PPT
introduction to the document object model- Dom chapter5
FLYMAN TECHNOLOGY LIMITED
 
PPT
Xml dom & sax by bhavsingh maloth
Bhavsingh Maloth
 
PPTX
The Document Object Model
Khou Suylong
 
PPT
DOM Quick Overview
Signure Technologies
 
PPTX
Dom in javascript
Mudasir Syed
 
PPTX
Introduction to DOM
Daniel Bragais
 
PPTX
XML Document Object Model (DOM)
BOSS Webtech
 
PPTX
Html dom & j query
hafeez1216
 
PPT
Understanding XML DOM
Om Vikram Thapa
 
PPTX
Understanding the dom by Benedict Ayiko
Damalie Wasukira
 
PPTX
INFT132 093 07 Document Object Model
Michael Rees
 
PPTX
Web1O1 - Session 1
NYCSS Meetup
 
PPTX
Presentation
Ninguno Ningun Otro
 
Introduction to the DOM
tharaa abu ashour
 
INTRODUCTION TO DOM AND DOM TREE
systematiclab
 
Document Object Model (DOM)
GOPAL BASAK
 
Document object model(dom)
rahul kundu
 
Document Object Model
chomas kandar
 
introduction to the document object model- Dom chapter5
FLYMAN TECHNOLOGY LIMITED
 
Xml dom & sax by bhavsingh maloth
Bhavsingh Maloth
 
The Document Object Model
Khou Suylong
 
DOM Quick Overview
Signure Technologies
 
Dom in javascript
Mudasir Syed
 
Introduction to DOM
Daniel Bragais
 
XML Document Object Model (DOM)
BOSS Webtech
 
Html dom & j query
hafeez1216
 
Understanding XML DOM
Om Vikram Thapa
 
Understanding the dom by Benedict Ayiko
Damalie Wasukira
 
INFT132 093 07 Document Object Model
Michael Rees
 
Web1O1 - Session 1
NYCSS Meetup
 
Presentation
Ninguno Ningun Otro
 

Viewers also liked (6)

PDF
Javascript and DOM
Brian Moschel
 
PPTX
JavaScript (without DOM)
Piyush Katariya
 
PPTX
[SoftServe IT Academy] JavaScript Forms
Ivan Matiishyn
 
PPT
JavaScript & Dom Manipulation
Mohammed Arif
 
PPT
DOM ( Document Object Model )
ITSTB
 
PDF
JSP 빠르게 시작하기
Park JoongSoo
 
Javascript and DOM
Brian Moschel
 
JavaScript (without DOM)
Piyush Katariya
 
[SoftServe IT Academy] JavaScript Forms
Ivan Matiishyn
 
JavaScript & Dom Manipulation
Mohammed Arif
 
DOM ( Document Object Model )
ITSTB
 
JSP 빠르게 시작하기
Park JoongSoo
 
Ad

Similar to JavaScript and DOM (20)

PPT
6867389.ppt
SunilChaluvaiah
 
PPT
6867389.ppt
SunilChaluvaiah
 
PPT
6867389 (1).ppt
SunilChaluvaiah
 
PPTX
Dom date and objects and event handling
smitha273566
 
DOCX
DOM(Document Object Model) in javascript
Rashmi Mishra
 
PPTX
Web technologies-course 09.pptx
Stefan Oprea
 
PPTX
WEB TECHNOLOGY Unit-4.pptx
karthiksmart21
 
PPT
Document Object Model
chomas kandar
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PPTX
DOM and Events
Julie Iskander
 
PDF
Intro to JavaScript
Jussi Pohjolainen
 
PPTX
Part 7
NOHA AW
 
PDF
Interacting with the DOM (JavaScript)
Florence Davis
 
PDF
Web 6 | JavaScript DOM
Mohammad Imam Hossain
 
PPTX
Javascript for web Programming creating and embedding with html
E.M.G.yadava womens college
 
PPTX
chap08 - Javascript. YfugffuuhuiDOM.pptx
MaxiAhiake
 
PDF
HTML_DOM
BIT DURG
 
PPTX
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
6867389.ppt
SunilChaluvaiah
 
6867389.ppt
SunilChaluvaiah
 
6867389 (1).ppt
SunilChaluvaiah
 
Dom date and objects and event handling
smitha273566
 
DOM(Document Object Model) in javascript
Rashmi Mishra
 
Web technologies-course 09.pptx
Stefan Oprea
 
WEB TECHNOLOGY Unit-4.pptx
karthiksmart21
 
Document Object Model
chomas kandar
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
DOM and Events
Julie Iskander
 
Intro to JavaScript
Jussi Pohjolainen
 
Part 7
NOHA AW
 
Interacting with the DOM (JavaScript)
Florence Davis
 
Web 6 | JavaScript DOM
Mohammad Imam Hossain
 
Javascript for web Programming creating and embedding with html
E.M.G.yadava womens college
 
chap08 - Javascript. YfugffuuhuiDOM.pptx
MaxiAhiake
 
HTML_DOM
BIT DURG
 
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
Ad

More from Jussi Pohjolainen (20)

PDF
Moved to Speakerdeck
Jussi Pohjolainen
 
PDF
Java Web Services
Jussi Pohjolainen
 
PDF
Box2D and libGDX
Jussi Pohjolainen
 
PDF
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
PDF
libGDX: Tiled Maps
Jussi Pohjolainen
 
PDF
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
PDF
Intro to Building Android Games using libGDX
Jussi Pohjolainen
 
PDF
Advanced JavaScript Development
Jussi Pohjolainen
 
PDF
Introduction to JavaScript
Jussi Pohjolainen
 
PDF
Introduction to AngularJS
Jussi Pohjolainen
 
PDF
libGDX: Scene2D
Jussi Pohjolainen
 
PDF
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
PDF
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
PDF
libGDX: User Input
Jussi Pohjolainen
 
PDF
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
PDF
Building Android games using LibGDX
Jussi Pohjolainen
 
PDF
Android Threading
Jussi Pohjolainen
 
PDF
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
PDF
Creating Games for Asha - platform
Jussi Pohjolainen
 
PDF
Intro to Asha UI
Jussi Pohjolainen
 
Moved to Speakerdeck
Jussi Pohjolainen
 
Java Web Services
Jussi Pohjolainen
 
Box2D and libGDX
Jussi Pohjolainen
 
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
libGDX: Tiled Maps
Jussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
Intro to Building Android Games using libGDX
Jussi Pohjolainen
 
Advanced JavaScript Development
Jussi Pohjolainen
 
Introduction to JavaScript
Jussi Pohjolainen
 
Introduction to AngularJS
Jussi Pohjolainen
 
libGDX: Scene2D
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: User Input
Jussi Pohjolainen
 
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Building Android games using LibGDX
Jussi Pohjolainen
 
Android Threading
Jussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Jussi Pohjolainen
 
Intro to Asha UI
Jussi Pohjolainen
 

Recently uploaded (20)

PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 

JavaScript and DOM

  • 1. Document  Object  Model  and   JavaScript   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. W3C  DOM   •  DOM  –  Document  Object  Model  –  cross-­‐ plaDorm  and  language-­‐independent   convenFon  for  interacFng  with  objects  in   HTML  and  in  XML.   •  With  DOM  you  can  manipulate  html/xml   document!  Dynamic  html!   •  Public  interface  available:  hPp://www.w3.org/ DOM/DOMTR    
  • 3. W3C  DOM  Levels   •  (  DOM  Level  0  and  Intermediate  DOM  )   –  Not  W3C  Standards,  used  in  Netscape  2  (Level  0)  and   Netscape  4  (Intermediate  DOM)     •  DOM  Level  1   –  1998:  Ability  to  change  enFre  HTML  or  XML  document   •  DOM  Level  2   –  2001:  Introduces  “getElementById”  funcFon,  event   model  and  support  for  XML  namespaces   •  DOM  Level  3   –  2004:  XPath,  keyboard  event  handling  
  • 5. DOM  Programming  Intro   •  DOM  is  a  model  that  describes  how  all   elements  in  an  html  page  are  related  to   topmost  structure:  document  itself   •  Can  influence  the  document   – See:  hPp://www.w3.org/TR/REC-­‐DOM-­‐Level-­‐1/ introducFon.html   •  Possible  to  read,  modify  and  delete  tags  
  • 6. Node   •  In  DOM,  each  object  is  Node   •  In  this   – <p>Hello</p>   •  You  have  two  nodes     – 1)  element  node  -­‐  p     – 2)  text  node  -­‐  "Hello"   •  Text  node  is  child  node  of  p  element.  P   element  is  parent  node  of  the  text  node  
  • 7. Node  Example   <p>This is a <strong>paragraph</strong></p> <p> | -------------- | | This is a <strong> | | paragraph
  • 8. APribute  Node   <a href=“http://www.tamk.fi”>TAMK</a> <a> ----------------- | | TAMK href | http://www.tamk.fi
  • 9. Different  Nodes   •  Element  node:  p,  img,  a   •  Text  node:  sometext   •  APribute  node:  src  
  • 10. DOM  Level  1:  To  Access  DOM  tree   •  X  can  be  some  node   – var parent = x.parentNode; – var firstchild = x.childNodes[0]; •  How  to  get  reference  to  x?  
  • 12. Access   var title = document.firstChild.firstChild.lastChild; // document.html.head.title var title = document.firstChild.childNodes[0].childNodes[ 0];
  • 13. Gelng  Element  Easier  Way   var x = document.getElementsByTagName(‘strong')[0] var x = document.getElementById('hereweare');  
  • 14. Changing  the  Node   // <a href=“” id=“someId”>Link</p> var x = document.getElementById(’someId'); x.firstChild.nodeValue = “Hello!”; x.setAttribute(“href”, “http:/…”);  
  • 15. Inner  HTML   // <a href=“” id=“someId”>Link</p> var x = document.getElementById(’someId'); x.innerHTML = “Hello!”; // innerHTML is NOT W3C Standard and it’s // slower…
  • 16. CreaFng  and  Removing  Nodes   var x = document.createElement(’hr'); document.getElementById('inserthrhere').appendChild(x); var node = document.getElementById('inserthrhere') node.removeChild(node.childNodes[0]); var x = document.createTextNode(’SomeText'); document.getElementById('hereweare').appendChild(x);
  • 17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> <script type="text/javascript"> //<![CDATA[ function change() { // Get list of ALL <h1> - elements var listOfHeading1 = window.document.getElementsByTagName("h1"); // Find the first <h1> - element in the list var heading1 = listOfHeading1[0]; // Get the child - element of the first <h1> - element (Text) var text = heading1.firstChild; // Replace the text text.data = "Hello from JS!"; } //]]> </script> </head> <body> <h1>Title</h1> <input type="submit" onClick="change();" value="click!"/> </body> </html>
  • 18. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /> <script type="text/javascript"> //<![CDATA[ function change() { // Reference to the table - element var table = document.getElementById("mytable"); var tr = document.createElement("tr"); // <tr> var td1 = document.createElement("td"); // <td> var td1Text = document.createTextNode("New Cell"); // "New Cell" td1.appendChild(td1Text); // <td>New Cell</td> var td2 = document.createElement("td"); // <td> var td2Text = document.createTextNode("New Cell"); // "New Cell" td2.appendChild(td2Text); // <td>New Cell</td> tr.appendChild(td1); tr.appendChild(td2); table.appendChild(tr); } //]]> </script> </head> <body> <table id="mytable" border="1"> <tr><td>&nbsp;</td><td>&nbsp;</td></tr> <tr><td>&nbsp;</td><td>&nbsp;</td></tr> <tr><td>&nbsp;</td><td>&nbsp;</td></tr> </table> <input type="submit" onClick="change();" value="Add Row"/> </body> </html>

Editor's Notes

  • #5: See:http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(Document_Object_Model)Trident: IE 4.0 -&gt;Tasman: IE For MacPresto: Opera