-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetElemenById.html
37 lines (36 loc) · 1.2 KB
/
getElemenById.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Change URL</title>
<script type="text/javascript">
function changeLink() {
let changedLink = 0;
if (changedLink == 0) {
//get Element with ID 'ChangeURL' in HTML to assign value
document.getElementById('ChangeURL').innerHTML = 'CIW Certified';
document.getElementById('ChangeURL').href = 'http://ciwcertified.com';
//we also can add attribute by using get Element ID
document.getElementById('ChangeURL').target='_blank';
changedLink++;
console.log(changedLink);
} else {
document.getElementById('ChangeURL').innerHTML =
'Microsoft';
document.getElementById('ChangeURL').href =
'http://microsoft.com';
document.getElementById('ChangeURL').target='_blank';
changedLink--;
console.log(changedLink);
}
}
</script>
</head>
<body>
<h2>CIW JavaScript Specialist</h2>
<h3>Change URL</h3>
<a id="ChangeURL"
href="http://www.microsoft.com">Microsoft</a><br>
<input type="button" value="Change Link" onClick="changeLink()">
</body>
</html>