Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var anchorTags = document.getElementsByTagName('a');
- var lenA = anchorTags.length;
- //first we hide all nested lists and attach onlcick event to all 'a' tags
- (function () {
- var nestedLists = document.querySelectorAll('ul ul');
- var len = nestedLists.length;
- for (var i = 0; i < len; i++) {
- nestedLists[i].style.display = "none";
- };
- for (var i = 0; i < lenA; i++) {
- anchorTags[i].addEventListener('click', expandOrCollapse);
- };
- }())
- //no we define the function that hides/shows the nested lists
- function expandOrCollapse() {
- if (this.nextElementSibling.style.display == 'none') {
- this.nextElementSibling.style.display = 'block';
- }
- else if (this.nextElementSibling.style.display == 'block') {
- this.nextElementSibling.style.display = 'none';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment