Tap Me!
function appendCustomDropdown() { // HTML template untuk dropdown const customDropdownHTML = `
`; // Menambahkan HTML di akhir atau bisa ke elemen lain document.body.insertAdjacentHTML('beforeend', customDropdownHTML); // Menambahkan fungsi dropdown const dropdownSelected = document.getElementById('dropdownSelected'); const dropdownList = document.getElementById('dropdownList'); dropdownSelected.addEventListener('click', () => { dropdownList.style.display = dropdownList.style.display === 'block' ? 'none' : 'block'; }); const options = dropdownList.querySelectorAll('div'); options.forEach(option => { option.addEventListener('click', () => { dropdownSelected.textContent = option.textContent; dropdownSelected.style.color = 'rgb(255, 0, 0)'; dropdownList.style.display = 'none'; const url = option.getAttribute('data-value'); if (url) { window.location.href = url; // Mengarahkan ke server yang dipilih } }); }); // Menutup dropdown jika klik di luar elemen window.addEventListener('click', (e) => { if (!dropdownSelected.contains(e.target) && !dropdownList.contains(e.target)) { dropdownList.style.display = 'none'; } }); } // Panggil fungsi untuk mengappend dropdown ke halaman appendCustomDropdown();