HTML - Manipulation


The DOM tree can be manipulated with scripts. Each element in the DOM tree is represented by an object, and these objects have APIs so that they can be manipulated.

For instance, a link (e.g. the a element in the tree above) can have its “href” attribute changed in several ways:

var a = document.links[0]; // obtain the first link in the document
a.href = 'sample.html'; // change the destination URL of the link
a.protocol = 'https'; // change just the scheme part of the URL
a.setAttribute('href', ''); // change the content attribute directly

Share this page:
Follow us:
Task Runner