- Notifications
You must be signed in to change notification settings - Fork 27.3k
/
Copy pathdom-example-manipulated.html
46 lines (40 loc) · 1.51 KB
/
dom-example-manipulated.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<htmllang="en-US">
<head>
<metacharset="utf-8">
<metaname="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple DOM example</title>
<style>
.highlight {
color: white;
background-color: black;
padding:10px;
width:250px;
text-align: center;
}
</style>
</head>
<body>
<section>
<imgsrc="dinosaur.png" alt="A red Tyrannosaurus Rex: A two legged dinosaur standing upright like a human, with small arms, and a large head with lots of sharp teeth.">
<p>Here we will add a link to the <ahref="https://www.mozilla.org/">Mozilla homepage</a></p>
</section>
<script>
constlink=document.querySelector('a');
link.textContent='Mozilla Developer Network';
link.href='https://developer.mozilla.org';
constsect=document.querySelector('section');
constpara=document.createElement('p');
para.textContent='We hope you enjoyed the ride.';
sect.appendChild(para);
consttext=document.createTextNode(' — the premier source for web development knowledge.');
constlinkPara=document.querySelector('p');
linkPara.appendChild(text);
// You could clone link para by doing something like this and inserting the new para instead
// var newPara = linkPara.cloneNode(true);
sect.appendChild(linkPara);
linkPara.parentNode.removeChild(linkPara);
para.setAttribute('class','highlight');
</script>
</body>
</html>