Skip to content
Advertisement

Tag: dom

How can I adjust the window innerwidth according to the percentage?

I try to adjust the window.innerwidth according to percentage but I don’t know what to do. MY goal is depending on the size of window.innerwidth, change the backgroundcolor of html. window.innerwidth can’t use percentages when comparing? I tried like this. Answer “90%” isn’t a valid value for innerWidth property. I think you meant 90% of outerWidth. Try out the following

Javascript failing to load properly when in

Code is not working and I can’t seem to figure out why. I have to keep the javascript in the html head because it is required and I believe that’s where im going wrong and it’s not loading properly.The window onload is something new for me and i’m not sure if that would be the correct way to use it

Using Spies and Mocks on complex objects with Jest

I’m fairly new to testing and writing tests for a currently uncovered javaScript codebase using Jest. The code covers some niche use cases, as its conditionally injected and executed by the browser during page load. Anyway, I’m having issues mocking up custom objects. Here’s the function in question: As far as I understand, I need to mock both window.location.pathname to

Why DOMContentLoaded handler can block first paint?

There is a similar question that wasn’t resolved. I’ve encountered a situation when handler that listens to DOMContentLoaded can block first paint. Sometimes it blocks, sometimes it doesn’t I tried many times cmd + R to see it. Is there any explanation to this behaviuor? Also I recordered a video to show this: https://www.youtube.com/watch?v=EDZQ1nLCK2w&feature=youtu.be When you see a blank page

Can I get the include path of the js file – within the js file?

Is it possible for a js function to figure out the file path of its code ? At runtime. Ex. <html><head><script src=”/js/version-3.2.1/myfile.js” /><head>…</html> /js/version-3.2.1/myfile.js Answer You can use document.currentScript: The Document.currentScript property returns the <script> element whose script is currently being processed and isn’t a JavaScript module. (For modules use import.meta instead.) It’s important to note that this will not

Save ID in variable and add style to it

I want to highlight randomly a word which is inside a <p> tag with the id=JShighlight. It should blink one time and then another randomly chosen word should blink.** I can’t add the css style needed to the ID. The words are nested in a span with an unique id like id=”one” oder id=”two”. Like: To chose a word randomly,

Get native HTML element in Cypress

How do I get an underlying native HTMLElement (or Element or Node…) from a Cypress query? I would like to access the native HTMLElement instance in el. I have tried el[0] but the result is of type any. Answer In cypress, first() is a command that will be chained to .get() and retry for that whole selection until timeout. That

querySelectorAll for element contain specific class

I have few divs that contain two classes such as this: where {{month.year + ‘-‘ + month.monthName + ‘-‘ + ‘end’}} for a certain month is 2018-August-end I want to select the divs that contain only 2018-August-end which I store into a variable so I tried something like this but I get this error Uncaught DOMException: Failed to execute ‘querySelectorAll’

Advertisement