Unable to work out the “setTimeout” function accordingly in JavaScript

Here’s the HTML ↓

<center>
  <div id="eventDiv" onmouseover="mouseSlideIn()" onmouseout="mouseSlideOut()">
    <div id="box"></div>
    <!--Above is the red box i.e. inside the main DIV-->
  </div>
</center>

Here’s the CSS ↓

body {
  background: grey;
  margin: 0;
}

#eventDiv {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 90vh;
  background: powderblue;
  border-radius: 20px;
  transition: 0.8s;
  transition-timing-function: ease;
}

#box {
  position: relative;
  background: red;
  height: 150px;
  width: 150px;
  transition: 0.5s;
  transition-timing-function: ease;
}

Here’s the JS ↓

function mouseSlideIn() {
  document.getElementById("box").style =
    "background: blue; height: 50px; width: 50px;";
}

function mouseSlideOut() {
  setTimeout(function () {
    document.getElementById("box").style = "";
    document.getElementById("eventDiv").style = "";
  }, 2000);
}

Goal :

  1. When I hover over the id="eventDIV" (outer most div), the id="box" must shrink and change color.
  2. When I hover out of the id="eventDIV" , the id="box" must return to its original size & color.
  3. But, before the box returns to its original state, I want a delay of (let’s say 2000ms ).
  4. This is achievable with the help of setTimeout function.

Problems :

  1. When I hover out of the id="eventDIV" before the setTimeout runs out which is 2000ms , it breaks the code.
  2. It doesn’t run appropriately when I hover over again (i.e.): Even when the cursor is inside the id="eventDIV" , the mouseSlideOut() function gets executed, which was supposed to be called on onmouseout event; that is when I hover out.
  3. It keeps repeating the same mistake until I refresh the code.

What have I tried :

  1. I have tried using clearTimeout function, but its doesn’t seems to help.
  2. Some other methods that didn’t work.

Note:

  • I am a novice in JS.
  • I don’t want any changes in CSS/pseudo elements ( :hover ).
  • I want to try it through JS (if possible).
  • This is just practice code, I am going to implement this elsewhere (if it works).
  • Thanks in advance.

Toggle navbar icon on click for small screen

I am new to coding. I am unable to create a navbar icon that changes on small screen when it is clicked.

I have tried using a bootstrap navbar, when I click the navbar on small screen, it only shows the navbar list but the icon doesn’t change.
actual result

I expect to have the navbar icon to change when clicked on small screen as in the image below.
expected outcome

Here is my code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
      integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
      crossorigin="anonymous"
    />
    <link
      rel="stylesheet"
      href="https://use.fontawesome.com/releases/v5.7.0/css/all.css"
      integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ"
      crossorigin="anonymous"
    />

    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <button
        class="navbar-toggler"
        type="button"
        data-toggle="collapse"
        data-target="#navbarSupportedContent"
        aria-controls="navbarSupportedContent"
        aria-expanded="false"
        aria-label="Toggle navigation"
      >
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item active">
          </li>
          <li class="nav-item active">
            <a class="nav-link" href="#"
              >Office <span class="sr-only">(current)</span></a
            >
          </li>
          <li class="nav-item active">
            <a class="nav-link" href="#"
              >Windows<span class="sr-only">(current)</span></a
            >
          </li>
          <li class="nav-item active">
            <a class="nav-link" href="#"
              >Xbox<span class="sr-only">(current)</span></a
            >
          </li>
          <li class="nav-item active">
            <a class="nav-link" href="#"
              >Support<span class="sr-only">(current)</span></a
            >
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Link</a>
          </li>
        </ul>

        <ul class="navbar-nav mr-auto">
          <li class="nav-item dropdown">
            <a
              class="nav-link dropdown-toggle"
              href="#"
              id="navbarDropdown"
              role="button"
              data-toggle="dropdown"
              aria-haspopup="true"
              aria-expanded="false"
              >All Microsoft</a
            >

            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
              <a class="dropdown-item" href="#">Action</a>
              <a class="dropdown-item" href="#">Another action</a>
              <div class="dropdown-divider"></div>
              <a class="dropdown-item" href="#">Something else here</a>
            </div>
          </li>
          <li>
            <a href="#" class="user"><i class="fas fa-search"></i></a>
          </li>
          <li>
            <a href="#" class="user"><i class="fas fa-shopping-cart"></i></a>
          </li>
          <li>
            <a href="#" class="user"><i class="far fa-user-circle"></i></a>
          </li>
        </ul>
      </div>
    </nav>

    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  </body>
</html>

I need help with this, I am new to Dev and Stackoverflow.

Accessibility screen reader reading number with trailing zeros

I’m working on making a ‘-‘ read as ‘to’ for a screen reader when reading an amount range.

I got it working using a screen reader only class, hiding the original text and writing what i want the screen reader to read in anther screen reader only span.

.sr-only {
border: 0 !important;
clip: rect(1px, 1px, 1px, 1px) !important;
-webkit-clip-path: inset(50%) !important;
clip-path: inset(50%) !important;
height: 1px !important;
margin: -1px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
width: 1px !important;
white-space: nowrap !important;

}

       "Here is an amounts range <span aria-hidden='true'>{formattedMinAmount}-{formattedMaxAmount}.</span><span class='sr-only'>{formattedMinAmount} to {formattedMaxAmount}</span>"

However, the screen reader reads the formattedMinAmount and formattedMaxAmount as
299.00 to 6,000.00 with .00 at the end. I want to have it read as 299 to 6,000.

Has anyone else encountered this problem before. It only reads the .00 with the spans added for screen reader only and I can’t figure out why. I’d love some help with this.

On @svgr/core import in the file I have problems with compiler

Importing the @svgr/core making problems with the application.

Saying this in command line:

Failed to compile.

./node_modules/@ampproject/remapping/dist/remapping.mjs
Can't import the named export 'GenMapping' from non EcmaScript module (only default export is available)

or in the console about all other imported modules in that file remapping.mjs.

I am just importing in my file like this:

import { svgr } from '@svgr/core';

And it is not called or used. As soon as I do this import is making problems.

This is how my webpack config file is looking:

module.exports = { module: { mode: 'production', // "production" | "development" | "none" resolve: { extensions: ['*', '.mjs', '.js', '.json'], }, rules: [ { test: /.svg$/i, issuer: /.[jt]sx?$/, use: ['@svgr/webpack'], }, { test: /.mjs$/, include: /node_modules/, type: 'javascript/auto', }, ], }, }

And my devDependencies:

  "devDependencies": {
    "@svgr/core": "6.5.1",
    "@svgr/webpack": "^6.5.1",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.0.1",
    "@testing-library/user-event": "^12.6.0",
    "@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
    "customize-cra": "^1.0.0",
    "customize-cra-react-refresh": "^1.1.0",
    "enzyme": "^3.11.0",
    "enzyme-to-json": "^3.6.2",
    "jest-environment-jsdom-sixteen": "^1.0.3",
    "lint-staged": "^10.5.3",
    "redux-devtools-extension": "^2.13.8",
    "redux-mock-store": "^1.5.4",
    "sass": "^1.49.0",
    "svg-url-loader": "^8.0.0",
    "svgo": "^3.0.2"
  }
}

Please let me know your thoguhts.

MutationObserver not firing on elements with role=”grid”

I’m attempting to carry out an accessibility fix on a table that has been poorly formatted using incorrect ARIA techniques.

To do this, I’ve written a MutationObserver to watch the page for instances of the table with role=”grid” and dynamically change this to role=”table”, which addresses an accessibility issue when navigating the table with a screen reader.

I’ve been able to use the MutationObserver on other elements for this app (e.g., to fix incorrect use of aria-labelledby and role=”group”) and in those cases, I use the same logic and the MutationObserver executes the callback function and successfully changes the ARIA attributes. However, I can’t understand why the MutationObserver is not identifying any role=”grid” elements here when they appear in the DOM.

Here is my MutationObserver code:



const callback = (mutationList, observer) => {
    try {
        for (const mutation of mutationList) {
            if (mutation.type === "attributes") {
                if (mutation.attributeName === 'role') {
                    if (mutation.target.getAttribute('role') == 'grid') {
                        /* Replace ARIA role='grid' with role='table' */
                        mutation.target.setAttribute('role', 'table');
                        console.log(`The ${mutation.attributeName} attribute was changed`
                            + ` from ${mutation.target} to`
                            + ` ${mutation.target.getAttribute(mutation.attributeName)}`);
                    }
                }
            } else if (mutation.type === 'childList') {
                for (const node of mutation.addedNodes) {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        if (node.hasAttribute('role')) {
                            if (node.getAttribute('role') == 'grid') {
                                /* Replace ARIA role='grid' with role='table' */
                                node.setAttribute('role', 'table');
                                console.log(`The ${mutation.attributeName} attribute was changed`
                                    + ` from ${mutation.target} to`
                                    + ` ${mutation.target.getAttribute(mutation.attributeName)}`);
                            }
                        }
                    }
                }
            }
        }
    } catch(e) {
        console.error(e.message);
    }
};



// Select the node that will be observed for mutations
const targetNode = document.body;

// Options for the observer (which mutations to observe)
const config = {
    attributes: true,
    attributesOldValue: true,
    childList: true,
    subtree: true};

// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(targetNode, config);


I can’t directly copy the HTML source from the app because it’s a proprietary app, but the structure of the role=”grid” object looks like this:

<div
  class="_xzy"
  role="grid"
  aria-rowcount="1"
  aria-colcount="11"
  id="HospitalityGrid"
  aria-multiselectable="true"
  aria-label="Hospitality"
  tabindex="0"
  style="height:
  250px; width: 720px;">
...
</div>

Just to anticipate any questions as to why I’m writing a MutationObserver to fix accessibility rather than requesting that the correct ARIA be implemented in the app itself, I don’t have access to the source code or developers and so I’m writing this fix as an extension/add-in to make it more accessible to screen reader users.

To summarise, I tried writing a MutationObserver to automatically catch and fix elements with incorrect ARIA attribute role=”grid”. Currently nothing is happening as the role=”grid” elements are not being identified by the MutationObserver callback function.

How do I get the title, date, and author of an article with a firefox extension?

I’m trying to create a Firefox extension that will open a popup and, when a button is clicked, change some text in the popup to include the author, title, and date of a an article (ie New York Times) by looking through the metadata.

Currently I have this in the popup.js in order to store the title of the article:

browser.tabs.query({currentWindow: true, active: true}).then((tabs) => {
    var currentTab = tabs[0];
    title = currentTab.window.document.querySelector("meta[property='og:title']");
});

But when I run the popup, it returns an error saying that currentTab.window cannot be defined.

How do I make multiple instances of a web page?

I am working in a team to create a app for this event comeing up. What we are doing now is creating a individual page for each session that happens at this event. For simplicity I will say that each page will have a Tittle(or session ID) and a specific room number.

How can I create a individual web page for each of my sessions with seperate and unique info on each page in the most simple way possible.

I am open to useing MySQL to pull information for each website however that is out of my skill level

I have been looking up how to dynamically create html code with JavaScript, but that seems to not be exactly what I want for it only shows how to duplicate the html code and not automatically fill the html code from a data base of some sort

NextJS app stops immediately after starting

I was working on a NextJS app for a few weeks, decided to upgrade my node version from 16.15.0 to 18.15.0.

After that when I run npm run dev the server starts with no errors displaying a message

ready - started server on 0.0.0.0:3000, url: http://localhost:3000

then stops immediately.

I downgraded to a version 18.14.2 but that didn’t help and it’s not running on a version 16.15.0 now as well, even when I create a new app.

Animate remove item from array list in ReactJS/NextJS 13

I have an array in a useReducer called uploads.files – it looks like this when It has files in it:

enter image description here

So currently you click the icon (the tick, soon to be a cross) to remove the item from the array list. This has a bunch of complicated stuff behind it that talks to an s3 bucket and runs the deleteObject commond, which is all working okay.

But when the array gets updated with the new list (the useReducer finds and removes that file from the array) the component gets updated and the whole UX part of it is quite abrupt as the list gets rerendered and the image just dissappears.

I really want to put a nice animation, either slide out or fade away or something, but I am not getting very as to how to do this in react. I found this answer here that seems to be on the right path as to what I want to do, but its not working and Im not sure how to proceed.

My current code is:

import '../../app/[locale]/fileUploadImagePreview.css'
    <div className="flex flex-row gap-5 justify-items-center items-baseline h-60 mb-10">
        { uploads.files.length > 0 ? (
            <>
                { uploads.files.map((file,index) => {
                    return (
                        <CSSTransition
                            in={uploads.files[index]}
                            timeout={{
                                enter: 0,
                                exit: 2000
                            }}
                            unmountOnExit
                            classNames="fileUploadImagePreview"
                        >
                            <FileUploadImagePreview
                                key={index}
                                file={file}
                                image={uploads.images[index]}
                                progress={uploads.progress[index]}
                                handleDeleteObject={() => handleDeleteObject(file)}
                            />
                        </CSSTransition>
                    )
                })}
            </>
            ) : (
            <div className="col-start-2 col-span-3">
                <Image src={emptyUploadIcon} width={300} alt="No files uploaded" className='align-text-bottom'/>
            </div>
        )}
    </div>

And the CSS (taken from the answer above and changed the name):

.fileUploadImagePreview-enter {
    opacity: 0;
}

.fileUploadImagePreview-enter-active {
    opacity: 1;
}
.fileUploadImagePreview-exit {
    opacity: 1;
}

.fileUploadImagePreview-exit-active {
    animation: foo 2s ease forwards;
    transform-origin: left;
}

@keyframes foo {
    from {
        opacity: 1;
        background: pink;
        transform: translate(0, 0);
        box-shadow: 0 0 2px 3px pink;
        color: red;
    }

    50% {
        transform: rotate(30deg) scale(2);
        background: coral;
        box-shadow: 0 0 2px 3px coral;
        color: limegreen;

    }

    to {
        opacity: 0;
        transform: scale(1);
        background: white;
        color: white;
    }
}

I’m not expecting anyone to write the whole code for me at all but point me in the right direction would fantastic. I need the CSS Transition to happen programmatically, so when I’m updating the files I could call a function that start the animation, then (i’m guessing) once its finished, callback and re-render the component.

I’m just not sure how to go about this.

I’m also using Tailwind if there’s an easier way to do it in that.

Python or JavaScript POST HTTP 1.1 error 404

I use python and JavaScript to make the website that you can register by linking with SQl. However, when I use the command flask run, there is POST /register HTTP 1.1 error. I can’t register on the website and the website shows “The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.”

I would like to know that is the py or js is incorrect or something with the server.

Thank you in advance

I would like to know that is the py or js is incorrect or something with the server.

Extract the value of href attribute

enter image description here

I want to extract all the emails from this HTML document. There are several entries. Each entry starts with a div and several span elements and the one having the email has the <a tag and has an href=”mailto:[email protected]
How can I use javascript to loop over and extract the href value for all these

Instagram Music Feature

how to create music feature like instagram in react js. And also which Vendor or music Api or SDK to use it.

No resources found. I tried to search on Google but no luck finding and resource to use it.

What way can I validate element contains text without failing test when the same element contains different text?

I have a scnearios where an element on a table changes from one text for example ‘staging..’ to a date for example today’s date ’10/03/2023′. It doesn’t change automatically so you would have to click on a apply button to see it is changed or not and it takes around 30 / 40 seconds to change. I want to check every 8 seconds by clicking Apply button that the column changes from ‘staging’ to today’s date.

So I have implemented a code like below –

enter image description here

The code works OK in terms of keep clicking Apply button every 8 secs. However, it fails due to the assertion -cy.get(‘td’).eq(1).contains(Staging...) changes.

Is there any way I can avoid the assertion and check this condition so the it doesn’t fail?

Many thanks in advace 🙂