I’m developing a chrome extension for manipulating HTML elements. I got a little problem. The element that I want to manipulate is without ID or ClassName, like this: I want to manipulate the width. But there is no identifier in the tag div. How can I manipulate that tag using javascript DOM? Answer You can use querySelector. Here is a
Tag: dom
Separate onClick event for parent and child element
I have JSX code like this: When I click on parent (outside the child) it will run clickOnParent, and when I click the child it will run both clickOnParent and clickOnChild of course.Now I want to trigger only clickOnChild and ignore clickOnParent when clicking exactly on the child. How can I do? Answer Use Event.stopPropagation()
why js closest method not find sibling element?
Note: as far as i know that closest() method searches up the DOM tree for the closest element which matches a specified CSS selector. When i click on margin space between two li element .. it’s return null… but if i replace margin-bottom: 15px; with padding-bottom… everything is okay… CSS Code Image if i click on red mark area.. it’s
why my last.addEventListener(“click”,nextLevel) not working?
https://codepen.io/demi-chen/pen/RwGPgxv I try to find the lastElementChild in the first div. It does show …… after I use console.log to check. why the addEventListener not working. I click the lastElementChild smile.png face but it’s not working. if function nextLevel() is working. the left&right side should add more smile.png. Tks! Answer its quite a simple fix really change your nextlevel to
Uncaught TypeError: Cannot read property ‘addEventListener’ of undefined error in my JS file
I gave my HTML codes on the top. JS Codes are on the down: In this case, When I hover over the cardBody element, the output must write “mouseenter”. And when I leave with the mouse, the output must “mouseover”. However, I get an error Uncaught TypeError: Cannot read property ‘addEventListener’ of undefined. I searched everywhere about this problem, but
Javascript attempt to keep sidebar at 100vh at all times
Working on a project requiring old-school CSS support and want to keep <aside> filling up the page by remaining the same height as the <article> element’s box (It may be between a header and footer, in which case it would not extend past them.) Here’s my attempt at dynamically setting the height. It doesn’t seem to work. This doesn’t work
Select an option in website’s mobile version (responsive mode)
How can I select a size option from https://www.supremenewyork.com/mobile#products/305278, when I’m browsing it in responsive mode? I tried it with document.querySelector(“#size-options > option:nth-child(2)”).selected = “selected”; but it doesn’t work. In desktop mode https://www.supremenewyork.com/shop/pants/n1to4psjk/wlmx7p5hr the method document.querySelector(“#size > option:nth-child(3)”).selected = “selected”; works as expected. Answer You can use document.querySelector(“#order_billing_country”).value = “countryCode”; and it will work on both desktop and mobile. The
Local Storage is overwritten instead of the new elements being added (JavaScript)
I want to storage an array of objects in local storage but I just can storage one object into the array. All the new objects are overwriting the previous one in index 0. This is my JavaScript code: Thanks in advance!! Answer get the current content of the local storage first and then put the new objects into the array.
Javascript create iFrame dom innerHTML
gives Error: Uncaught TypeError: Cannot read property ‘body’ of undefined how can i fix this? Answer to add content to iframe, you should pass by src attribute, here is an example. if your content is url, you put it directly into src,like this
Displaying and hiding of loader div not working synchronously as intended in Javascript
I want a loader element to show while my Sudoku solver function is running and hide upon completion. However, what happens in practice is that the loader never shows itself (or shows and hides almost instantly) even while the solver function is running. The timer for showing performance seems to be working and acting synchronously while the loader isn’t, leading