Using getElementsByClassName instead of getElementById.

This commit is contained in:
Kartik Gupta
2016-10-12 22:03:36 +05:30
parent 78b0b5d229
commit 8f4536f605
2 changed files with 10 additions and 4 deletions

View File

@@ -7,11 +7,11 @@
</head>
<body>
<p id="history-title">History for <span id="domain1"></span> (Last 5 results) :</p>
<p id="history-title">History for <span class="domain"></span> (Last 5 results) :</p>
<div></div>
<p id="history"></p>
<div></div>
<p><a href="#" id="clear">Clear history for <span id="domain2"></span></a></p>
<p><a href="#" id="clear">Clear history for <span class="domain"></span></a></p>
<script src="history.js"></script>
</body>

View File

@@ -2,11 +2,17 @@
function get_hostname(url) {
var a = document.createElement('a');
a.href = url;
document.getElementById('domain1').innerHTML = a.hostname;
document.getElementById('domain2').innerHTML = a.hostname;
set_domain(a.hostname);
return a.hostname;
}
function set_domain(domain) {
spans = document.getElementsByClassName('domain');
[].slice.call(spans).forEach(function(span) {
span.innerHTML = domain;
});
}
function no_history(hostname) {
document.getElementById('history').innerHTML = `No history for ${hostname}.`;
}