Skip to content
TheChatArchiveThe Chat Archive
grok-3-preview-02-24· xAIHugging Face LMArena Human Preference 140K

// Function to highlight the current page in the navbar function highlightCurrentPage()…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash’s answer.
  1. User

    // Function to highlight the current page in the navbar function highlightCurrentPage() { // Get the current page filename const currentPage = window.location.pathname.split('/').pop() || 'index.html'; // Default to index.html if no filename

    // Find all nav links const navLinks = document.querySelectorAll('.nav-links a');

    // Loop through links and add 'active' class to the current page navLinks.forEach(link => { const href = link.getAttribute('href'); if (href === currentPage) { link.classList.add('active');

      // Add active class to SVG icons
      const svgIcons = link.querySelectorAll('.magnifying-glass, .home-icon');
      svgIcons.forEach(icon => {
        icon.classList.add('active-icon');
      });
      
      // If this is in a dropdown, also highlight parent
      const parentDropdown = link.closest('.dropdown');
      if (parentDropdown) {
        const parentLink = parentDropdown.querySelector('.dropdown-toggle');
        if (parentLink) {
          parentLink.classList.add('active-parent');
        }
      }
    }
    

    }); }

    Modify this funktion to also add the active atribute to the .logo class

  2. Assistant

    Here's the modified function that adds the active attribute to the .logo class when on the index.html page:

    // Function to highlight the current page in the navbar
    function highlightCurrentPage() {
      // Get the current page filename
      const currentPage = window.location.pathname.split('/').pop() || 'index.html'; // Default to index.html if no filename
      
      // Find all nav links
      const navLinks = document.querySelectorAll('.nav-links a');
      
      // Find the logo element
      const logo = document.querySelector('.logo');
      
      // Loop through links and add 'active' class to the current page
      navLinks.forEach(link => {
        const href = link.getAttribute('href');
        if (href === currentPage) {
          link.classList.add('active');
          
          // Add active class to SVG icons
          const svgIcons = link.querySelectorAll('.magnifying-glass, .home-icon');
          svgIcons.forEach(icon => {
            icon.classList.add('active-icon');
          });
          
          // If this is in a dropdown, also highlight parent
          const parentDropdown = link.closest('.dropdown');
          if (parentDropdown) {
            const parentLink = parentDropdown.querySelector('.dropdown-toggle');
            if (parentLink) {
              parentLink.classList.add('active-parent');
            }
          }
        }
      });
      
      // Add active class to logo if on index.html
      if (logo && currentPage === 'index.html') {
        logo.classList.add('active');
      }
    }
    

    The modifications include:

    1. Added a new constant logo that queries for the element with class 'logo'
    2. Added a new conditional block at the end that checks if:
      • The logo element exists (logo)
      • The current page is 'index.html' (currentPage === 'index.html')
    3. If both conditions are true, it adds the 'active' class to the logo

    This modification will highlight the logo only when you're on the index.html page. If you want to highlight the logo on other pages as well, you can modify the condition. For example:

    • To highlight logo on all pages, remove the currentPage === 'index.html' condition
    • To highlight logo on specific pages, you could use an array of page names:
    const highlightLogoPages = ['index.html', 'home.html', 'main.html'];
    if (logo && highlightLogoPages.includes(currentPage)) {
        logo.classList.add('active');
    }
    

    Remember to call this function when the page loads, typically with:

    document.addEventListener('DOMContentLoaded', highlightCurrentPage);
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.