HANSONGTSENG (Talk | contribs) (original template js) |
HANSONGTSENG (Talk | contribs) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | + | function dropdown1(){ | |
+ | document.getElementById('dropdowncontent1').classList.toggle('notshow'); | ||
+ | console.log('here!') | ||
+ | } | ||
− | + | function dropdown2(){ | |
− | + | document.getElementById('dropdowncontent2').classList.toggle('notshow'); | |
+ | } | ||
− | + | function dropdown3(){ | |
− | + | document.getElementById('dropdowncontent3').classList.toggle('notshow'); | |
− | + | } | |
− | + | function dropdown4(){ | |
− | + | document.getElementById('dropdowncontent4').classList.toggle('notshow'); | |
− | + | } | |
− | + | function dropdown5(){ | |
− | + | document.getElementById('dropdowncontent5').classList.toggle('notshow'); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | window.onclick = function(event){ | |
− | + | var contents = document.getElementsByClassName("dropdowncontent"); | |
− | + | var buttons = document.getElementsByClassName("dropdownbutton"); | |
− | + | for (var i = contents.length - 1; i >= 0; i--) { | |
− | + | if(!(event.target.id==buttons[i].id)){ | |
− | + | if (!contents[i].classList.contains('notshow')) { | |
− | + | contents[i].classList.add('notshow'); | |
− | + | } | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
} | } | ||
− | + | } | |
− | + | ||
− | + | ||
− | + |
Latest revision as of 13:00, 28 May 2018
function dropdown1(){ document.getElementById('dropdowncontent1').classList.toggle('notshow'); console.log('here!') }
function dropdown2(){ document.getElementById('dropdowncontent2').classList.toggle('notshow'); }
function dropdown3(){ document.getElementById('dropdowncontent3').classList.toggle('notshow'); } function dropdown4(){ document.getElementById('dropdowncontent4').classList.toggle('notshow'); } function dropdown5(){ document.getElementById('dropdowncontent5').classList.toggle('notshow'); }
window.onclick = function(event){ var contents = document.getElementsByClassName("dropdowncontent"); var buttons = document.getElementsByClassName("dropdownbutton"); for (var i = contents.length - 1; i >= 0; i--) { if(!(event.target.id==buttons[i].id)){ if (!contents[i].classList.contains('notshow')) { contents[i].classList.add('notshow'); } } } }