-
Notifications
You must be signed in to change notification settings - Fork 0
/
faqs.js
executable file
·56 lines (46 loc) · 1.58 KB
/
faqs.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";
var $ = function(id) { return document.getElementById(id); };
var current = null;
// the event handler for the click event of each a element
var toggle = function() {
var link = this; // they clicked a tag
var h2 = link.parentNode; // h2 tag that contains a tag
var div = h2.nextElementSibling; // h2 tag's sibling div tag
var h2Elements = faqs.getElementsByTagName("h2");
for (var i = 0; i < h2Elements.length; i++ ) {
if( h2Elements[i].hasAttribute("class"))
{
//h2Elements[i].className="";
h2Elements[i].removeAttribute("class");
h2Elements[i].nextElementSibling.removeAttribute("class");
}
}
// toggle plus and minus image in h2 elements by adding or removing a class
if (h2.hasAttribute("class")) {
// h2.removeAttribute("class");
h2.className = "";
} else {
// h2.setAttribute("class", "minus");
h2.className = "minus";
}
// toggle div visibility by adding or removing a class
if (div.hasAttribute("class")) {
div.className = "";
} else if (current !== div) {
current = div;
div.className = "open";
} else {
current = null;
}
};
window.onload = function() {
// get the a tags
var faqs = $("faqs");
var linkElements = faqs.getElementsByTagName("a");
// attach event handler for each a tag
for (var i = 0; i < linkElements.length; i++ ) {
linkElements[i].onclick = toggle;
}
// set focus on first <a> tag
linkElements[0].focus();
};