News Articles DOM

How to set visibility in react typescript on page load

I am creating a cookie consent in a react app where users can accept or reject. If the user has already accepted the cookie concept, dont show again. I want to check on page load if the item is already set, don’t display consent else display(html to hidden). But the issue is that onLoad event, […]

Vue changes to array not updating the DOM

I’m trying to make changes to an array in the parent component (insert and update data) that is passed to the child component via Props, but the DOM is not being updated. Parent component: <UsersList v-for="(role, i) in userRolesNames" :key="i" :users="usersPages[i].data" /> Child component: <template> <div v-for="user in users" :key="user.id" > <span>{{ user.name }}</span> <div> […]

Value change in DOM but not render in UI

when I change the value of lang than in dom value and placeholder of background textupdated as per my language but not in UI. Below img I update my language in the first tab and it updates the background value and placeholder in the contact information tab but not render in UI. is this because […]

Mousedown event for non-button + Correct format for memory game

I have repeatedly attempted to use a mousedown listener for this memory game, but it won’t work. Also, I feel there is a way to do the game with my layout of the game itself. async function eachRounds() { for (let i = 0; i < rounds; i++) { for (let j = 0; j […]

Access the content of browser extension popup window

I want to access the content of the popup window from the browser extension using javascript from my site. My purpose is to listen to if a button is clicked from the popup window. How can this be achieved? Source: JavaSript – Stack Overflow

Unexpected DOM Ordering Behaviour With Element.prepend on Infinite Slider-Track Animation

I’m working on an infinite slider but I’m experiencing a strange bug with DOM ordering. At the end of each animation iteration, the last child element is supposed to be prepended to the div.slider-track element so it renders at the beginning of the slider and pushes up the other cards before the next iteration. It […]

Adding link to image with a function

For my schoolproject I need to make a moviefilter website. The filter mechanics work. Now I need to add a function which I can use to link the images to their corresponding IMDB page by using the IMDB ID that is found in my big movie const. In there it’s also called imdbID: "idtag". A […]

Capture the flag (CTF) with HTTP cookies

I’m trying to get past this CTF challenge. Here is the clue: The challenge here to steal someone else’s cookies from a different website. The value of that cookie is your password. You are using a chat application with Bob wherein you send and receive messages from each other. You know Bob uses BookFace.com to […]

How to Remove and Add same event listener in React onClick to not stack them up infinitely?

I’m trying to remove and add the same event listener in onClick React event, so when the target element is clicked, an event listener is added to the parent element. On the next click it should get removed to not stack. Right now I know that a new function gets created each click, so the […]

How can I show a text-output from javascript innerhtml in a div-box without the text overflowing and with html/css styling

I am using [vis.js library][1] to display a network. When you click on a node it should display an info-text about the node in the div-box on the right. Somehow the text which is collected from the javascript and send to the divbox using *.innerhtml* is not being wrapped inside the div-box and I can’t […]

HTML contenteditable: Keep Caret Position When Inner HTML Changes

I have a div that acts as a WYSIWYG editor. This acts as a text box but renders markdown syntax within it, to show live changes. Problem: When a letter is typed, the caret position is reset to the start of the div. const editor = document.querySelector(‘div’); editor.innerHTML = parse(‘**dlob** *cilati*’); editor.addEventListener(‘input’, () => { […]

textContent in JavaScript not showing the correct output

On the left is the results from textContent Just a bit of context from the image. I am trying to manipulate DOM by invoking the textContent to the window everytime the user clicks the button while also logging it in the terminal. However, let’s say if I click scissor and then click the rock button […]

My Javascript doesn’t seem to be working – could the DOM have changed?

Like many of us, I want to keep my code as DRY as possible – and that includes my website. I would like to do this by importing the common footer onto all pages – which is fine, and I’m doing this as follows: page.html <html> <head> <script type="text/javascript"> $(function(){ $("#footer").load("./Components/footer.html"); }); </script> </head> <body> […]

table scrollable body header columns not aligned with the body columns

I have a simple table that has varying lengths of data in columns The tabular data looks like this. CODEPEN 1 codepen basic tabular data My requirement is to scroll the tbody content while keeping the header at the top. I have achieved that like this. CODEPEN 2 scrollable tabular data The problem here is […]

Javascript, GetElementById element is not defined?

For some reasons, I can’t display #coupon with javascript, when i try to get elementById it displays the error message elementById undefined, HTML <html> <head> <title>Exercise</title> <link rel="stylesheet" href="stylesheet.css"> <script src="javascript.js"></script> </head> <body> <div class="inputi"> <p class="input-text">Une Jam?</p> <input placeholder="Sheno emrin…" type="text" id="inputId"> //checks input value <button type="button" onclick="getInputValue()">Vazhdo</button> // shows error message if it […]

Why are elements not rendered in the order listed in the markup?

I am learning D3. Here I have a set of charts and a button to control it. In the HTML – the button appears before all the charts. However, on the page – the first chart appears above the button. There is no other CSS applied to them. I would expect the button to show […]

Build shopping cart functions with vanilla Javascript

I am trying to build a shopping cart function. I have a product page, that displays API data. When pressing the "Add to cart" button, the item should be added to local storage, and fetched from local storage to build the html content for the shopping cart. The cart page should display this: A list […]

Hiding html dynamically toggling visibility vs creating dynamically with javascript when needed – best practice

I have a list that I expect to always display to a user, but not until the user generates certain events (i.e. clicking on something). <ol id=’list’> <li class=’item’></li> <li class=’item’></li> <li class=’item’></li> </ol> Once a certain action is taken, I will have textContent for each of the list items, which I will insert at […]

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.