mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 06:48:37 +02:00
Using getElementsByClassName instead of getElementById.
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
@@ -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}.`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user