website_rasmus/js/datacoop.js

17 lines
795 B
JavaScript
Raw Normal View History

2019-02-12 12:18:48 +00:00
window.onload = function(e) {
var details = document.querySelectorAll("section.service-details");
for (var detail of details) {
var toggle = document.createElement("a");
var service_name = detail.previousElementSibling.querySelector("a").text;
toggle.text = "Læs mere om " + service_name;
2019-02-12 12:18:48 +00:00
toggle.onclick = function(e) {
e.preventDefault();
var service_name = e.target.previousElementSibling.previousElementSibling.querySelector("a").text;
var hide = e.target.previousElementSibling.classList.toggle("hidden");
e.target.text = (hide ? "Læs mere om " : "Skjul detaljer om ") + service_name;
2019-02-12 12:18:48 +00:00
}
detail.insertAdjacentElement('afterend', toggle);
detail.classList.add("hidden");
}
}