JAVASCRIPT fetching of HTML li text content [closed]

I am working on an api project, and I need to gather the contents of the li using my javascript. There can be multiple of these li‘s

My html (just a small section)

<div>
    <button id="roomListButton">Click me to see what rooms your in</button>
        <ul id="roomsList">

        </ul>
            
</div>

My javascript (not everything)

const roomsListR = document.querySelector('#roomsList');

const delRoomButTEMPLATE = document.createElement('button')
delRoomButTEMPLATE.classList.add('deleteRoomBtn');
delRoomButTEMPLATE.innerHTML = `Leave this room`;


      const fetchRoomsAndProcess = async (event) => {
            console.log('fetching rooms')
            event.preventDefault();

            const response = await fetch('/getRooms');
            const jsonResponse = await response.json();
            const result = jsonResponse.result

            // Preparatory clean of the rooms list
                roomsListR.innerHTML = ``
            
            for (let i = 5; i != 0; i--) {
                let currentRoom = result.splice(0, 1)
                let currentRoom2 = currentRoom[0]
                let currentRoom3 = currentRoom2['roomname']
                console.log('currentRoom3 : ', currentRoom3);

                // Now do the stuff with currentRoom
                const li = document.createElement('li');
                li.innerHTML = `${currentRoom3} ${delRoomButTEMPLATE.outerHTML}`

                li.addEventListener('click', (event) => {
                    console.log('button clicked.')
                    const parent = event.target.parentNode
                    console.log(parent.innerHTML)
                })

                roomsListR.appendChild(li)

                if (result.length == 0) {
                    break
                }
            }

        }

The syntax: li.textContent does not work as it returns the text content of the button element inside it as well. li.innerText for some reason does the same thing. And li.innerHTML includes the tag which is not what I want.

Is there a shortcut for retrieving just the text in the node, not including any tags or anything inside of those tags?

Redirection problem in NextJs notfound-page not working

i am new to nextjs and i am trying to build a small website. I am trying to make it multilingual with /it and /el so right now i have a locale folder with all my nested folders and pages. my main page.tsx is now in locale folder so the domain/ redirects me to domain/el as el is the default. but the main issue is that the only route in root is “domain”/Admin and nothing else and here is the problem: if i write “domain”/ssadsdha which means something random word the app gets me to domain/random but it shows me the homepage and not the not-found.tsx i tried using a custom notfound page and the default but still. the weird thing is that the notfound.tsx works if i write domain/random/random etc.. but not in domain/kfndk , I even tried adding a root page.tsx to redirect all users to the /el domain but still doesnt work

JAVASCRIPT fetching of HTML li text content

I am working on an api project, and I need to gather the contents of the li using my javascript. There can be multiple of these li‘s

My html (just a small section)

<div>
    <button id="roomListButton">Click me to see what rooms your in</button>
        <ul id="roomsList">

        </ul>
            
</div>

My javascript (not everything)

const roomsListR = document.querySelector('#roomsList');

const delRoomButTEMPLATE = document.createElement('button')
delRoomButTEMPLATE.classList.add('deleteRoomBtn');
delRoomButTEMPLATE.innerHTML = `Leave this room`;


      const fetchRoomsAndProcess = async (event) => {
            console.log('fetching rooms')
            event.preventDefault();

            const response = await fetch('/getRooms');
            const jsonResponse = await response.json();
            const result = jsonResponse.result

            // Preparatory clean of the rooms list
                roomsListR.innerHTML = ``
            
            for (let i = 5; i != 0; i--) {
                let currentRoom = result.splice(0, 1)
                let currentRoom2 = currentRoom[0]
                let currentRoom3 = currentRoom2['roomname']
                console.log('currentRoom3 : ', currentRoom3);

                // Now do the stuff with currentRoom
                const li = document.createElement('li');
                li.innerHTML = `${currentRoom3} ${delRoomButTEMPLATE.outerHTML}`

                li.addEventListener('click', (event) => {
                    console.log('button clicked.')
                    const parent = event.target.parentNode
                    console.log(parent.innerHTML)
                })

                roomsListR.appendChild(li)

                if (result.length == 0) {
                    break
                }
            }

        }

The syntax: li.textContent does not work as it returns the text content of the button element inside it as well. li.innerText for some reason does the same thing. And li.innerHTML includes the tag which is not what I want.

Is there a shortcut for retrieving just the text in the node, not including any tags or anything inside of those tags?

Why Symbols and BigInt can’t be instancied using “new” keyword? [duplicate]

While I was learning the language, I became interested in primitive types and their object wrappers.

While I was in my code editor discovering this language feature, I discovered that any of these object wrappers could be instantiated with the keyword “new.” I then discovered that not using it (new) transforms this “constructor” into a conversion function. Very well, the documentation tells me that this is an intentional feature of the language.

However, as I continued testing, I realized that trying to instantiate the BigInt and Symbol wrapper objects was impossible (returns a TypeError).

So, I went to read the documentation, and it clearly states that:

  • Attempting to construct it with new throws a TypeError.
  • Performs a type conversion when called as a function rather than as a constructor (like all other object wrappers).
  • Is not intended to be used with the new operator or to be subclassed.

But nothing more!

The question I’m asking myself is: Why can all other wrapper objects be instantiated with the keyword new except for BigInt and Symbol?

My hypothesis was that in the symbol example, it is a bit of a special case in the sense that it is not “intended” to be manipulated, hence the instantiation.

Sorry for this long message, I feel like the answer is obvious and, worse, right in front of my eyes.

PS: I know that I will never instantiate wrapper objects in JavaScript in a real-world situation, I’m just wondering because I’m curious about what happens under the hood.

By the way, if you have any anecdotes or websites that explain in detail how things work, I’d love to hear them.

How does using Date.now() inside useMemo prevent optimizations?

My main question is: I want to understand why adding Date.now() inside useMemo seems to break the optimization. As far as I know, a React component wrapped with React.memo only re-renders if its props change, so in this case, it should re-render only when items or onItemClick change. And when items changes, useMemo will recompute processedItems anyway because the array reference is different.

So why does it matter whether Date.now() is included or not?

Can someone please explain what I’m missing here? It seems like a simple question, but I’ve been struggling to fully understand this for days.

const ExpensiveComponent = React.memo(({ items, onItemClick }) => {
  const processedItems = useMemo(() => {
    return items.map((item) => ({
      ...item,
      processed: true,
      timestamp: Date.now(),
    }));
  }, [items]);
  return (
    <div>
      {" "}
      {processedItems.map((item) => (
        <div key={item.id} onClick={() => onItemClick(item)}>
          {item.name}
        </div>
      ))}{" "}
    </div>
  );
});

I tried logging with and without Date.now(), and the outputs appeared essentially the same, except that the timestamps are missing when it’s not included which is the expected result.

Object.entries(item) as [keyof TCreate,TCreate[keyof TCreate]][]

I understand that keyof TCreate gives a union of all keys in the type TCreate. But I’m confused about `TCreate[keyof TCreate]`. What exactly does it represent, why do we write it this way, and how does it work in TypeScript? I don’t fully get how it handles the values of the object and why it produces a union of all possible value types instead of preserving the specific type for each key

How to have two instances of jQuery .load?

I know next to nothing about JS at the minute, I use this to import images from a separate HTML file into a DIV but I don’t know how to add a second path where I can have the same thing again but from a different file into a different DIV

Copying this block of code didn’t work, but I don’t know how to add it to the same script if you get what I mean.

<script type="text/javascript">
 jQuery(document).ready(function(){
   jQuery("#taskmarquee").load("/pagebuttons.html #PageBtns");
 });
</script>

Does modern JavaScript/TypeScript have ways to conditionally “swap” code when being bundled if features are avaiable?

Do JavaScript bundlers (or TypeScript) have some kind of feature that allows to bundle the code and “swap” some lines if specific features are available, like #ifdef macros in C or C#?

I have the following function, in this form should be compatible with any modern JS engine and browser. My target is to ensure this function always work.

public dispatch(): IteratorObject<(event: T) => void, void, void> {
    const listeners = [...this.#_listeners];
    return (function *() { for (const listener of listeners) yield listener; })();
}

Since March 2025 the new Iterable.from method (and other too) have been introduced and the MDN page says is newly available with modern browsers too.

The function from before could be rewritten like so:

public dispatch(): IteratorObject<(event: T) => void, void, void> {
    return Iterator.from([...this.#_listeners]);
}

And now the rewritten function only works with the most recent update or from an engine that supports the method.

Some scripts I’ve seen fix a similar problem with a constant at the top of the script that checks if a feature is avaiable and either use one of two method that use different features. then this is used inside the script.

Does modern JavaScript bundlers or TypeScript support for a more “literal” (if that’s how to be called) way to replace lines of code depending on version or features available?

Notes:

  • The this.#_listeners is an array.

  • The showcased functions returns IteratorObject because that’s the common class between a generator and Iterator.from

In a html document, How to make sure that body is the only scrollable ancestor?

I have a document in which absolutely positioned divs get attached to the dom and removed from the dom. Sometimes, the newly attached divs are either partially visible or not visible at all. So I have to use the scrollintoview method as described here. But I need to have css setting to make sure that the scrolling happens with respect to body. So, my question is, How to make sure that body is the only scrollable ancestor?

REFERENCE: mdn web page there is reference to “scrollable ancestor”

Firing a button when its container is about to be hidden

I’m building a simple menu with a collection of buttons. The first button toggles a class which is use show or hide the following div full of more buttons. That part works.

The tricky part is closing the menu when I click out. From various questions around SO, I get the solution of doing the following:

  • Set the tabindex on the menu container.
  • Set the focus on the menu container when the menu is opened.
  • use onblur to toggle off the class which opens the menu.

That part also works, but the buttons no longer work.

I’m guessing that the onblur happens first, and that closing the menu prevents the button from firing. If I disable the class toggle, then the button will fire.

I have tried using onclick as well as addEventListener with both true an false. Nothing helps.

Any suggestions on how I can get the button to fire before the menu closes?

let menu = document.querySelector('div#menu');
menu.setAttribute('tabindex',1);

let toggle = menu.querySelector('button#toggle');
toggle.onclick = event => {
  toggle.classList.toggle('open');
  menu.focus();
};

menu.querySelector('button#apple').onclick = event => {
  console.log('apple');
};
menu.querySelector('button#banana').addEventListener('click', event => {
    console.log('banana');
}, false);
menu.querySelector('button#cherry').addEventListener('click', event => {
    console.log('cherry');
}, true);

//  hide when clicked off
    menu.onblur = event => {
      console.log('byebye');
      toggle.classList.toggle('open', false);
    };
div#menu {
  position: relative;
  button#toggle+div {
    position: absolute;
    display: none;
    flex-direction: column;
  }
  
  button#toggle.open+div {
    display: flex;
  }
}
<div id="menu">
  <button id="toggle">Things</button>
  <div>
    <button id="apple">Apple</button>
    <button id="banana">Banana</button>
    <button id="cherry">Cherry</button>
  </div>
</div>
<p>Some stuff</p>

How to convert cubemap to equirectangular projection JavaScript

I need to convert these six separate cubemap tiles to an equirectangular projection. I’m not familiar with THREE or anything, I just want to use these images with photo-sphere-viewer.

    function convert(bubbliURL) {
  const bubbliId = new URL(bubbliURL).pathname.replaceAll("/", ""),
        directions = ["nx", "ny", "nz", "px", "py", "pz"];

      for (const direction of directions) {
        const image = new Image;
        image.onload = () => document.body.append(image);
        image.src = `https://d39cwcjmzdw2iw.cloudfront.net/${bubbliId}/stitched_${direction}.jpg`;
  }
}

convert("http://on.bubb.li/561309a7zrtjetjc40ojhie");
img { width: 40%; }

How to remove material from STL file? [closed]

CLICK HERE FOR PICTURE OF EXPECTED OUTCOME

CLICK HERE FOR A PREVIEW OF RED CYLINDER TOOL BIT

https://codepen.io/Maximusssssu/pen/dPGyrrP?editors=1000

https://drive.google.com/file/d/1knlg1YN5MFQIG8uY8YmnXAPHmysvKQ-Y/view?usp=sharing

Dear readers, I have created an interactive webpage where users can upload an STL file and also move a red cylinder created at the origin in the 3d dimension (+X,-X ,+Y,-Y,+Z,-Z) . For simplicity, assume that the red cylinder is a mill bit or basically a circular knife that can cut through anything. When the user move the red cylinder into or on the surface of the STL solid, how do i create the visualization of cutting as seen in the picture of my expected outcome above.

I have provided all the necessary files including the STL model that can be downloded for testing.

  function createHole() {
    // TODO: Students should implement the cut creation functionality here
    // Hint: You'll need to:
    // 1. Check if clickedPoint and stlMesh exist
    // 2. Create a cylinder geometry for the cut
    // 3. Position it at the clicked point
    // 4. Use CSG operations to subtract the cylinder from the STL mesh
    // 5. Update the scene with the new mesh
    
    alert('CREATE CUT function needs to be implemented!');
  }

work post survey super easy and fun 5 questions

NEED DATA FOR PROJECT PLEASE ANYTHING HELPS

I WANT DATA AND I NEED DATA

https://docs.google.com/forms/d/e/1FAIpQLScvX8uACIg7zqUQ8vXpFxg6WIWZhjXmIP8tMVagS7_IBnza_Q/viewform

THIS IS FOR A GRADE ITS STRAIGHT TO THE POINT, 5 EASY QUESTIONS,
DID I MENTION ITS A PROJECT THATS FOR A GRADE. ITS ABOUT WORK I KNOW WORK SUCKS BUT PLEASE FILL IT OUT ANYTHING HELPS I NEED ATLEAST 2000 RESPONSES TO GET ACCURATE DATA
NO IM NOT A BOT NO IM NOT AN AI YES YOU WILL FEEL GOOD ABOUT YOURSELF HELPING ME

How to remove material from STL file?

CLICK HERE FOR PICTURE OF EXPECTED OUTCOME

CLICK HERE FOR A PREVIEW OF RED CYLINDER TOOL BIT

https://codepen.io/Maximusssssu/pen/dPGyrrP?editors=1000

https://drive.google.com/file/d/1knlg1YN5MFQIG8uY8YmnXAPHmysvKQ-Y/view?usp=sharing

Dear readers, I have created an interactive webpage where users can upload an STL file and also move a red cylinder created at the origin in the 3d dimension (+X,-X ,+Y,-Y,+Z,-Z) . For simplicity, assume that the red cylinder is a mill bit or basically a circular knife that can cut through anything. When the user move the red cylinder into or on the surface of the STL solid, how do i create the visualization of cutting as seen in the picture of my expected outcome above.

I have provided all the necessary files including the STL model that can be downloded for testing.

  function createHole() {
    // TODO: Students should implement the cut creation functionality here
    // Hint: You'll need to:
    // 1. Check if clickedPoint and stlMesh exist
    // 2. Create a cylinder geometry for the cut
    // 3. Position it at the clicked point
    // 4. Use CSG operations to subtract the cylinder from the STL mesh
    // 5. Update the scene with the new mesh
    
    alert('CREATE CUT function needs to be implemented!');
  }