-
Notifications
You must be signed in to change notification settings - Fork 0
/
46.image_object.html
121 lines (86 loc) · 2.6 KB
/
46.image_object.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html>
<head>
<title>Image Object</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" href="styles.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3.css">
<link href="prism.css" rel="stylesheet" />
<script src="scripts/prism.js"></script>
<style>
* {
box-sizing: border-box;
}
</style>
</head>
<body class="w3-margin">
<h1>Image Object</h1>
<img src="images/flowers1.jpg" id="flowers" alt="pretty flowers" height="275" width="350" />
<h2>Alternate Text</h2>
<p>Get the alt text for an image:</p>
<button onclick="myFunction1()">Get Text</button>
<p id="demo1"></p>
<script>
function myFunction1() {
var x = document.getElementById("flowers").alt;
document.getElementById("demo1").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction1() {
var x = document.getElementById("flowers").alt;
document.getElementById("demo1").innerHTML = x;
}
</code></pre>
<hr />
<h2>Height</h2>
<p>Get the height of an image:</p>
<button onclick="myFunction2()">Get Height</button>
<p id="demo2"></p>
<script>
function myFunction2() {
var x = document.getElementById("flowers").height;
document.getElementById("demo2").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction2() {
var x = document.getElementById("flowers").height;
document.getElementById("demo2").innerHTML = x;
}
</code></pre>
<hr />
<h2>Get Source</h2>
<p>Get the value of the source attribute:</p>
<button onclick="myFunction3()">Get Source</button>
<p id="demo3"></p>
<script>
function myFunction3() {
var x = document.getElementById("flowers").src;
document.getElementById("demo3").innerHTML = x;
}
</script>
<pre><code class="language-javascript">
function myFunction3() {
var x = document.getElementById("flowers").src;
document.getElementById("demo3").innerHTML = x;
}
</code></pre>
<hr />
<h2>Replace</h2>
<img src="images/flowers1.jpg" id="flowers2" alt="pretty flowers" height="275" width="350" />
<p>Replace the image by changing its source attribute:</p>
<button onclick="myFunction4()">Change Image</button>
<script>
function myFunction4() {
document.getElementById("flowers2").src="images/flowers2.jpg";
}
</script>
<pre><code class="language-javascript">
function myFunction4() {
document.getElementById("flowers2").src="images/flowers2.jpg";
}
</code></pre>
</body>
</html>