How to do a wildcard element name match with “querySelector()” or “querySelectorAll()” in JavaScript?

[id^=’someId’] will match all ids starting with someId. [id$=’someId’] will match all ids ending with someId. [id*=’someId’] will match all ids containing someId. If you’re looking for the name attribute just substitute id with name. If you’re talking about the tag name of the element I don’t believe there is a way using querySelector

How do I capture a CTRL-S without jQuery or any other library?

An up to date answer in 2020. Since the Keyboard event object has been changed lately, and many of its old properties are now deprecated, here’s a modernized code: document.addEventListener(‘keydown’, e => { if (e.ctrlKey && e.key === ‘s’) { // Prevent the Save dialog to open e.preventDefault(); // Place your code here console.log(‘CTRL + … Read more

Do events handlers on a DOM node get deleted with the node?

Event handler functions are subject to the same Garbage Collection that other variables are. That means they will be removed from memory when the interpreter determines that there is no possible means to obtain a reference to the function. Simply deleting a node however does not guarantee garbage collection. For instance, take this node and … Read more

Screen Coordinates of a element, via Javascript

window.screenX/Y are not supported on IE. But for other browsers, a close approximation of position is: var top = $(“#myelement”).offset().top + window.screenY; var left = $(“#myelement”).offset().left + window.screenX; Exact position depends on what toolbars are visible. You can use the outer/innerWidth and outer/innerHeight properties of the window object to approximate a little closer. IE doesn’t … Read more

Open new window without focus on it [duplicate]

What you seek is called a “pop-under” window Open a new window using let handle = window.open() Lose focus of the new window by using handle.blur() The return focus to your existing window using window.focus() Example: var handle = window.open(‘https://stackoverflow.com/’); handle.blur(); window.focus(); However, it’s not a guarantee as user browser settings may override this behavior, … Read more

White spaces are required between publicId and systemId

The error message is actually correct if not obvious. It says that your DOCTYPE must have a SYSTEM identifier. I assume yours only has a public identifier. You’ll get the error with (for instance): <!DOCTYPE persistence PUBLIC “http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd”> You won’t with: <!DOCTYPE persistence PUBLIC “http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd” “”> Notice “” at the end in the second one … Read more

Replacement for deprecated `keypress` DOM event

Since the event is deprecated, you should avoid using it in new code, and plan on removing it from old code. The W3C specification says this about deprecated features: Features marked as deprecated are included in the specification as reference to older implementations or specifications, but are OPTIONAL and discouraged. Only features which have existing … Read more