Skip to content

Tag: dom

HTML5 event for `onselectionchange`

Is there a standard cross-browser HTML5 event which corresponds to IE legacy onselectionchange (so it is fired when the current selection changes)? EDITED, I’m looking to track Selection object changes. Answer use onchange I recommend using jQuery to avoid these cross browser issues, but that does not m…

Keep the sort order

I have a object with that values : And when I would like to show it Chrome reorders it based on the Index : It becomes : I wish to keep the order as it was when pushing! or reorder based on field “order” Can someone please help with that? Answer JavaScript objects are by definition unordered. If y…

Fire onblur event before onchange event

I have a large form that contains several text input fields. Essentially, I need to handle the onchange event for all fields and the onblur events for some fields. When a change is made to a field and the field loses focus, both events fire (which is the correct behavior). The only issue is that I would like …

Appending a DOM element twice (jQuery)

Can someone explain why the following snippet does not add <foo> to both #a and #b? HTML: JS: jsfiddle Edit: thanks for the helpful points, the fact that .append() moves the element explains this behavior. Since the element in my application is actually a Backbone View’s .el, I prefer not to clone…

Insert value to input / JavaScript

I have the following JS / HTML code: I want that after I upload file, the file-name will shown in the tput text, but this cide doesn’t work. How can I fix it? Update : The file name should be inside the input text Answer Move your script element before the input element. You had better put the script el…

Check if class exists somewhere in parent

I want to check if a class exsits somewhere in one of the parent elements of an element. I don’t want to use any library, just vanilla JS. In the examples below it should return true if the element in question resides somewhere in the childs of an element with “the-class” as the class name. …

How to correctly iterate through getElementsByClassName

I am Javascript beginner. I am initing web page via the window.onload, I have to find bunch of elements by their class name (slide) and redistribute them into different nodes based on some logic. I have function Distribute(element) which takes an element as input and does the distribution. I want to do someth…