-
Notifications
You must be signed in to change notification settings - Fork 50
/
style-toggle.js
36 lines (28 loc) · 1.05 KB
/
style-toggle.js
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
(function() {
var defaultStyleText = 'default spec. style';
var additionalStyleText = "additional spec. style";
var toggle;
function toggleStyle() {
var st = document.getElementById('st');
if (st.hasAttribute('disabled') === true) {
st.removeAttribute('disabled');
st.disabled = false;
toggle.textContent = defaultStyleText;
} else {
st.setAttribute('disabled', 'true');
st.disabled = true;
toggle.textContent = additionalStyleText;
}
}
window.onload = function() {
var st = document.getElementById('st');
var divHead = document.getElementById('div-head');
var defaultText = defaultStyleText;
toggle = document.createElement('a');
divHead.insertBefore(toggle, divHead.firstChild);
toggle.textContent = defaultText;
toggle.setAttribute('class', 'toggle');
toggle.setAttribute('href', '#');
toggle.addEventListener("click", toggleStyle, false);
};
})();