JavaScript Notes 5
JavaScript Notes 5
https://software.hixie.ch/utilities/js/live-dom-viewer/
DOM2.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>DOM2</title>
</head>
<body>
<h3>Source element:</h3>
<p id="source">
<style>
#source {
color: red;
}
#text {
text-transform: uppercase;
}
</style>
<span id="text">Take a look at<br />how this text<br />is
interpreted below.</span>
<span style="display:none">HIDDEN TEXT</span>
</p>
<h3>Result of textContent:</h3>
<textarea id="textContentOutput" rows="6" cols="30"
readonly>…</textarea>
<h3>Result of innerText:</h3>
<textarea id="innerTextOutput" rows="6" cols="30"
readonly>…</textarea>
<h3>Result of innerHTML:</h3>
<textarea id="innerHTML" rows="6" cols="30" readonly>…</textarea>
<script>
const source = document.getElementById("source");
const textContentOutput =
document.getElementById("textContentOutput");
const innerTextOutput =
document.getElementById("innerTextOutput");
const innerHTMLOutput = document.getElementById("innerHTML");
textContentOutput.value = source.textContent;
innerTextOutput.value = source.innerText;
innerHTMLOutput.value = source.innerHTML;
</script>
</body>
</html>
OUTPUT:
DOM3
<!DOCTYPE html>
<html lang="en">
<head>
<title>DOM3</title>
</head>
<body>
<div id='source'>
This element
is <strong>strong</strong> and has some super fun
<code>code</code>!
</div>
<h3>Result of textContent:</h3>
<textarea id="textContentOutput" rows="6" cols="30"
readonly>…</textarea>
<h3>Result of innerText:</h3>
<textarea id="innerTextOutput" rows="6" cols="30"
readonly>…</textarea>
<h3>Result of innerHTML:</h3>
<textarea id="innerHTML" rows="6" cols="30" readonly>…</textarea>
<script>
const source = document.getElementById("source");
const textContentOutput =
document.getElementById("textContentOutput");
const innerTextOutput =
document.getElementById("innerTextOutput");
const innerHTMLOutput = document.getElementById("innerHTML");
textContentOutput.value = source.textContent;
innerTextOutput.value = source.innerText;
innerHTMLOutput.value = source.innerHTML;
</script>
</body>
</html>
OUTPUT:
<head>
<body>
<div id="page">
<h1 id="header">List</h1>
<h2>Buy groceries</h2>
<ul>
<li id="one" class="hot"><em>Paneer</em> Dosa</li>
<li id="two" class="hot">Nimbu Pani</li>
<li id="three" class="hot">Rava Dosa </li>
<li id="four">Filter Coffee </li>
</ul>
</div>
</body>
</html>
Dom_update.js
var ul = document.getElementsByTagName('ul')[0];
ul.appendChild(li_new);
li_new.className = 'new';
// Removing Element