Advertisement
swimmerbhs

script.js

Feb 19th, 2025
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Get elements
  2. const searchButton = document.getElementById('searchButton');
  3. const searchInput = document.getElementById('searchInput');
  4. const searchModal = document.getElementById('searchModal');
  5. const closeBtn = document.getElementsByClassName('close')[0];
  6.  
  7. // Search button click event
  8. searchButton.addEventListener('click', function() {
  9.     const query = searchInput.value;
  10.     const cseElement = document.createElement('div');
  11.     cseElement.className = 'gcse-searchresults-only';
  12.     searchModal.querySelector('#cse').appendChild(cseElement);
  13.     google.search.cse.element.render({
  14.         div: cseElement,
  15.         tag: 'searchresults-only',
  16.         gname: 'gSearchResults',
  17.     });
  18.     searchModal.style.display = 'block';
  19. });
  20.  
  21. // Close button click event
  22. closeBtn.onclick = function() {
  23.     searchModal.style.display = 'none';
  24. }
  25.  
  26. // Close modal when clicking outside
  27. window.onclick = function(event) {
  28.     if (event.target === searchModal) {
  29.         searchModal.style.display = 'none';
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement