document.addEventListener('DOMContentLoaded', function() {
    var searchResult = document.getElementById('datafetch');
    searchResult.style.display = 'none'; // Hide the search result initially
});

document.addEventListener('click', function(event) {
    var searchForm = document.getElementById('searchform');
    var searchResult = document.getElementById('datafetch');
    
    // Check if the click is inside the search form or the search result
    if (searchForm.contains(event.target) || searchResult.contains(event.target)) {
        return; // Allow default behavior if clicked inside the search form or the search result
    } else {
        searchResult.style.display = 'none'; // Hide the search result if clicked outside
    }
});

// Add event listener to show the search result when clicking on the search bar
document.getElementById('keyword').addEventListener('click', function(event) {
    var searchResult = document.getElementById('datafetch');
    searchResult.style.display = 'block'; // Show the search result when clicking on the search bar
});

// Add event listener to prevent the search result from hiding when clicking inside it
document.getElementById('datafetch').addEventListener('click', function(event) {
    event.stopPropagation(); // Stop the event from propagating to the document click event listener
});