Presentation is loading. Please wait.

Presentation is loading. Please wait.

Document Object Model (DOM) JavaScript manipulation of the DOM.

Similar presentations


Presentation on theme: "Document Object Model (DOM) JavaScript manipulation of the DOM."— Presentation transcript:

1 Document Object Model (DOM) JavaScript manipulation of the DOM

2 DOM Tree Some text Go.

3 DOM Tree Title box text Not in paragraph

4 DOM Tree Title This is italic bold text.

5 DOM Tree Link Not a link

6 JavaScript – document object JavaScript code is always executed in a web browser in the context to a rendered document. – In English, JavaScript is inside a web page (XHTML document). The document object refers to the XHTML document itself. var x = document.FunctionName(); – x is usually a “node” object. – or a text object.

7 How to manipulate content Title Paragraph Heading Another one var d = document.getElementById(‘content’); var h2s = d.getElementByTagName(‘h2’); var secondH2 = h2s[1]; var x = secondH2.innerHTML; // x would store “Another one” secondH2. innerHTML= “New one”; // The line above actually changes the live displayed web page.

8 How to manipulate attributes Home var h = document.getElementByID(‘homelink’).getAttribute(‘href’); alert(h); var x = document.getElementByID(‘homelink’); x.setAttribute(‘href’, ‘http://www.espn.com’); x.setAttribute(‘alt’, ‘Siena College’);

9 Creating Document structure x = document.createElement(‘body’) – makes a new element/tag – x.createTextNode(‘hi’) – add text inside a tag – hi

10 Append x.appendChild(document.createElement(‘h2’)) – hi x.insertBefore(document.createElement(‘h1’)) – hi Also, – removeChild – must identify the node by using getElementByID or TagName – cloneChild – must identify the node, can copy the entire tree below the node.


Download ppt "Document Object Model (DOM) JavaScript manipulation of the DOM."

Similar presentations


Ads by Google