Skip to content

Commit 6727cf7

Browse files
committed
newdomFiles.txt
1 parent 410ef37 commit 6727cf7

8 files changed

+171
-0
lines changed

dom 1 - method.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//dom method
2+
3+
<html>
4+
<body>
5+
6+
<h2>My First Page</h2>
7+
8+
<p id="demo"></p>
9+
10+
<script>
11+
document.getElementById("demo").innerHTML = "same here!";
12+
</script>
13+
14+
</body>
15+
</html>

dom 2 find elements by tagname.html

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// dom document finding elements by tagname:
2+
3+
<!DOCTYPE html>
4+
<html>
5+
<body>
6+
7+
<h2>JavaScript HTML DOM</h2>
8+
9+
<p>Finding HTML Elements by Tag Name.</p>
10+
<p>This example demonstrates the <b>getElementsByTagName</b> method.</p>
11+
12+
<p id="demo"></p>
13+
14+
<script>
15+
const element = document.getElementsByTagName("p");
16+
17+
document.getElementById("demo").innerHTML = 'The text in first paragraph (index 0) is: ' + element[0].innerHTML;
18+
19+
</script>
20+
21+
</body>
22+
</html>
23+
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
//finding elements by class name
3+
<!DOCTYPE html>
4+
<html>
5+
<body>
6+
7+
<h2>JavaScript HTML DOM</h2>
8+
9+
<p>Finding HTML Elements by Class Name.</p>
10+
<p class="intro">Hello World!</p>
11+
<p class="intro">This example demonstrates the <b>getElementsByClassName</b> method.</p>
12+
13+
<p id="demo"></p>
14+
15+
<script>
16+
const x = document.getElementsByClassName("intro");
17+
document.getElementById("demo").innerHTML =
18+
'The first paragraph (index 0) with class="intro" is: ' + x[0].innerHTML;
19+
</script>
20+
21+
</body>
22+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
//finding specific element
3+
<!DOCTYPE html>
4+
<html>
5+
<body>
6+
7+
<h2>JavaScript HTML DOM</h2>
8+
9+
<p>Finding HTML Elements by Query Selector</p>
10+
<p class="intro">Who's there !.</p>
11+
<p class="intro">This example demonstrates the <b>querySelectorAll</b> method.</p>
12+
13+
<p id="demo"></p>
14+
15+
<script>
16+
const x = document.querySelectorAll("p.intro");
17+
document.getElementById("demo").innerHTML =
18+
'The first paragraph (index 0) with class="intro" is: ' + x[0].innerHTML;
19+
</script>
20+
21+
</body>
22+
</html>

dom 5 - change html content.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//to change paras value for instance or changing html content.
2+
<!DOCTYPE html>
3+
<html>
4+
<body>
5+
6+
<h2>JavaScript can Change HTML</h2>
7+
8+
<p id="p1">Hello World!</p>
9+
10+
<script>
11+
document.getElementById("p1").innerHTML = "New text!";
12+
</script>
13+
14+
<p>The paragraph above was changed by a script.</p>
15+
16+
</body>
17+
</html>

dom 6 - change html attribute.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
//changing html attribute
3+
<!DOCTYPE html>
4+
<html>
5+
<body>
6+
7+
<h2>JavaScript HTML DOM</h2>
8+
<img id="image" src="smiley.gif" width="160" height="120">
9+
10+
11+
<script>
12+
document.getElementById("image").src = "landscape.jpg";
13+
</script>
14+
15+
<p>The original image was smiley.gif, but the script changed it to landscape.jpg</p>
16+
17+
</body>
18+
</html>

dom 7 - dynamic html attribute.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
//dynamic html attribute
3+
<!DOCTYPE html>
4+
<html>
5+
<body>
6+
7+
<p >since in the past time the time were wed sep 26 2022 11:24:54 GMT+0500 (Pakistan Standard Time) </p>
8+
9+
10+
<p id="demo">since in the past time the time were wed sep 26 2022 11:24:54 GMT+0500 (Pakistan Standard Time) </p>
11+
12+
<script>
13+
document.getElementById("demo").innerHTML = "Date : " + Date();
14+
</script>
15+
16+
</body>
17+
</html>
18+

dom 8 - submit a form.html

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
// js dom form
3+
<!DOCTYPE html>
4+
<html>
5+
<body>
6+
7+
<h2>JavaScript Validation</h2>
8+
9+
<p>Please input a number between 1 and 10:</p>
10+
11+
<input id="numb">
12+
13+
<button type="button" onclick="myFunction()">Submit</button>
14+
15+
<p id="demo"></p>
16+
17+
<script>
18+
function myFunction() {
19+
// Get the value of the input field with id="numb"
20+
let x = document.getElementById("numb").value;
21+
// If x is Not a Number or less than one or greater than 10
22+
let text;
23+
if (isNaN(x) || x < 1 || x > 10) {
24+
text = "Input not valid";
25+
} else {
26+
text = "Input OK";
27+
}
28+
document.getElementById("demo").innerHTML = text;
29+
}
30+
</script>
31+
32+
</body>
33+
</html>
34+
35+
36+

0 commit comments

Comments
 (0)