Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

transform this to vanilla js…

  1. User

    transform this to vanilla js

    document.querySelector(“#container”).addEventListener(“mousemove”, function(e) { parallaxIt(e, “.slide”, -100); parallaxIt(e, “img”, -30); });

  2. Assistant

    document.querySelector("#container").addEventListener("mousemove", function(e) { parallaxIt(e, ".slide", -100); parallaxIt(e, "img", -30); });

  3. User

    check if page has duplicated css ids

  4. Assistant

    To check if a web page has duplicated CSS IDs, you can use the following Vanilla JavaScript code:

    function checkDuplicateIds() {
      var ids = {};
      var duplicatedIds = [];
    
      // Get all elements with an ID attribute
      var elementsWithIds = document.querySelectorAll("[id]");
    
      // Loop through each element
      elementsWithIds.forEach(function(element) {
        var id = element.id;
    
        // Check if the ID has already been found
        if (ids[id]) {
          duplicatedIds.push(id);
        } else {
          ids[id] = true;
        }
      });
    
      // Return the duplicated IDs, if any
      return duplicatedIds;
    }
    
    // Usage
    var duplicatedIds = checkDuplicateIds();
    
    if (duplicatedIds.length > 0) {
      console.log("The following IDs are duplicated: " + duplicatedIds.join(", "));
    } else {
      console.log("No duplicated IDs found.");
    }
    

    This code defines a function checkDuplicateIds that checks for duplicated IDs in the web page. It uses the querySelectorAll method to retrieve all elements with an ID attribute, and then loops through each element to check if the ID has already been found. If a duplicated ID is found, it is added to an array duplicatedIds. Finally, the code logs the duplicated IDs if any are found.

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