I have a web application that is embedded in an iframe by external sites, of which we have no control over. Is there a way to detect when the iframe element has been removed from the dom of the parent, in order to perform some cleanup before it’s gone? It appears to fire a “visibilitychange” event, but I need to
Tag: dom
Jest with vanilla JS – tesing generated elements on DOM
Searched a lot online but cant find the best way to get an element’s innerHTML and just compare it with the results that should be rendered (I’m trying to compare with string) what I’m trying is adding some whitespace and test failed so I’m guessing there is better ways Also, unable to query a specific element generated inside body, why?
Property ‘id’ does not exist on type ‘Node’ in plain JS after cloneNode
I’ve got a pure JS function that adds a message to the page based on a chunk of “template” HTML. VS code is complaining about clone.id and clone.classList as a Node cannot have those properties. Now every answer and tutorial I’ve seen about cloning a chunk of HTML like this basically says to do exactly what I’m doing. I can
Get the hierarchy of a XML element with XPath
I am trying to get the ordered list of the hierarchy of a given element in a “application/xml” response.data document that I parse using a DOM parser in Javascript. So the expression should return the list [‘Grand Parent’,’Parent’,’Target’] for each A tag that has no A children. So I will get a list of lists where the last element of
Rewrite MutationObserver() with async/await
How can I write this mutation observer code, using async/await? I want to return true after console.log(“Button is appearing…”);. Could someone show me the best way to write this code? I also need to clarify, this code is watching for a button, which appears and then disappears. And the reappears again, multiple times. So the mutationObserver, is watching for the
Javascript click event doesnt accept two same function
I want to use joinLobby(‘create’) and joinLobby(‘join’) functions in one page. But when I reload the page, joinLobby function working instantly. How can I prevent instant work? Answer Just having the functions like that runs them instantly. Try something like this:
How To identify which Div is displaying the scrollbar
My dashboard app is a single page – never longer than 100vh. In a certain place, when I click a button, some unknown container temporarily overflows and a scrollbar appears on the right side, and then one second later it disappears. During that one second, the page background jumps very noticeably. I wish to prevent this scrollbar from displaying via
How to mount a Vue instance to a not yet appended HTML element
In an app I’m creating I want to mount a Vue instance to an HTML Node. But after using the $mount function, the Node doesn’t contain the Vue instance. In the code below you can see what I’m trying to accomplish. I want to return an HTML Node containing the Vue instance. Does anybody have an idea how to mount
How do I capture the user input via a number button they press?
I’m building a calculator app and like the title states, I want to find a way where I can store my ‘display value’ in a variable to be used in math functions (+ – * /). The buttons do display as expected but the next use case would be to capture that value and place it in a variable. Let
use “this” in a function passed to eventListener
Hello people I was refactoring some code and couldn’t figure a way to reuse the ‘this’: a/ Code I have b/ I want to move the function to another file and export it as: and use it like: but ‘this’ is undefined.. how do I bind it? Answer Pass this as parameter to function (and also decouple from event too):