Skip to content

Tag: dom

Edit DOM element in var before append it

I have a function that appends elements to the page who calls it using a template, like this: I have a function parameter that says which of the appended element sections is visible and which is not. So what I want to do is access to an element in the test variable like I do with jQuery and disable it.

How to copy a DOM node with event listeners?

I tried It doesn’t seem to copy the event listeners that I added using node.addEventListener(“click”, someFunc);. We use the Dojo library. Answer cloneNode() does not copy event listeners. In fact, there’s no way of getting hold of event listeners via the DOM once they’ve been at…

window.onload include images

Does window.onlaod include image load? or I must use another event for it? I want use ajax call to get HTML document which contains images, but I want show this document when all images are loaded. Answer it does include all webpage’s resource’s load – more information here: https://develope…

When is an event.target.value not a string?

I came accross value = String(event.target.value || “”) when a textinputs keyup/keydown event is fired. But i’m not sure when the event.target.value is not a string? Is this possible? When is something else passed off as an event.target.value? Answer If the event.target element is not an inp…

How to swap DOM child nodes in JavaScript?

What is the easiest way to swap the order of child nodes? For example I want childNode[3] to be childNode[4] and vice-versa. Answer There is no need for cloning. You can just move one node before the other. The .insertBefore() method will take it from its current location and insert it somewhere else (thus mo…