Get computed value of CSS variable that uses an expression like calc

Technically you cannot because the computed value is not static and will depend on other properties. In this case it’s trivial since we are dealing with pixel value but imagine the case where you will have percentage value. Percentage is relative to other properties so we cannot compute it until it’s used with var(). Same … Read more

Trigger form submission with javascript

Update Nov 21, 2022 I would now recommend the requestSubmit() method. You can pass a submit button to it if you want. Its cleaner and can be intercepted. document.getElementById(“myForm”).requestSubmit(); Original answer A custom event works just fine. document.getElementById(“myForm”).dispatchEvent(new CustomEvent(‘submit’, {cancelable: true}));

JSON.stringify is ignoring object properties

When an object has its own toJSON() implementation, JSON.stringify() uses the object returned from that method and stringifies that. kendo.data.Model defines it’s own toJSON() method which only returns the properties defined on the model, which is why you aren’t seeing other values (e.g. dirty, id, uid) in the string result. “If the stringify method sees … Read more

HTML5 Canvas: Get Event when drawing is finished

Like almost all Javascript functions, drawImage is synchronous, i.e. it’ll only return once it has actually done what it’s supposed to do. That said, what it’s supposed to do, like most other DOM calls, is queue-up lists of things to be repainted next time the browser gets into the event loop. There’s no event you … Read more

Is it possible to determine if a GeoJSON point is inside a GeoJSON polygon using JavasScript?

Seems like d3 has you covered: https://github.com/d3/d3-geo#geoContains d3.geoContains(object, point) Returns true if and only if the specified GeoJSON object contains the specified point, or false if the object does not contain the point. The point must be specified as a two-element array [longitude, latitude] in degrees. For Point and MultiPoint geometries, an exact test is … Read more

In the VS Code “Debug Console”, run a JavaScript await function

VS Code Debug Console supports top level async/await (https://github.com/microsoft/vscode-js-debug#top-level-await) however the issue might be you’re paused on the breakpoint. if you use await while paused on a breakpoint, you’ll only get a pending Promise back. This is because the JavaScript event loop is paused while on a breakpoint.

Adding and Removing Event Listeners with parameters

This is invalid: arr[i].el.addEventListener(‘click’, do_something(arr[i])); The listener must be a function reference. When you invoke a function as an argument to addEventListener, the function’s return value will be considered the event handler. You cannot specify arguments at the time of listener assignment. A handler function will always be called with the event being passed as … Read more