Skip to content
Advertisement

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

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

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

Advertisement