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

How do I tell if a DOM element is HTML or SVG?

You may try something like the following: if(document.getElementById(“el”) instanceof SVGElement) { console.log(“It’s an SVG element”); } <svg xmlns=”http://www.w3.org/2000/svg” xmlns:xlink=”http://www.w3.org/1999/xlink” width=”300″ height=”300″> <g id=”firstGroup”> <rect id=”el” width=”100″ height=”50″ x=”40″ y=”20″ fill=”blue” /> <text x=”40″ y=”100″>This is a basic SVG document!</text> </g> </svg> Note that the <svg> element itself is actually an HTML element containing SVG elements … Read more

JavaScript DOMParser access innerHTML and other properties

Your current method fails, because HTML properties are not defined for the given XML document. If you supply the text/html MIME-type, the method should work. var string = ‘<!DOCTYPE html><html><head></head><body>content</body></html>’; var doc = new DOMParser().parseFromString(string, ‘text/html’); doc.body.innerHTML; // or doc.querySelector(‘body’).innerHTML // ^ Returns “content” The code below enables the text/html MIME-type for browsers which do … Read more

How to get all the links of a list inside a div?

$(‘#blogPagination’).find(‘a’).attr(‘href’); This should find all a elements in the specified area, the get the href of them, assuming that you’ve already got jQuery and all that good stuff set up. If you have multiple a elements, you could do something like this: $(‘#blogPagination’).find(‘a’).each(function() { console.log($(this).attr(‘href’)); }); This will print out each href of each a … Read more

Vue.js: event after v-for is done

I had a similar issue but I took a different approach using the vue.nextTick(). I needed to be sure the v-for had finished rendering as the component will not re-render immediately, It will update on the next “tick” when the queue is empty. Vue.component(‘message’, { data() { return { message: [] } }, methods: { … Read more

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

jQuery difference between :eq() and :nth-child()

:eq() Select the element at index n within the matched set. The index-related selectors (:eq(), :lt(), :gt(), :even, :odd) filter the set of elements that have matched the expressions that precede them. They narrow the set down based on the order of the elements within this matched set. For example, if elements are first selected … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)