My objective is to change the background color of a columns in a table without addressing each data entry individually by Id or Name. I know there are several ways to do this, and I’ve tried 3 to be exact, and I’m having problems with each. For the sake of simplicity and clarity, In this question, I’m asking how to
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 mean you should skip testing. see here. Look at Rangy window.getSelection = rangy.getSelection
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 you need
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 to handle
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 it. Answer Because using append actually moves the
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 element
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. I think it would be
How to scroll down with Phantomjs to load dynamic content
I am trying to scrape links from a page that generates content dynamically as the user scroll down to the bottom (infinite scrolling). I have tried doing different things with Phantomjs but not able to gather links beyond first page. Let say the element at the bottom which loads content has class .has-more-items. It is available until final content is
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 something like this (as outlined for example here
Inject CSS stylesheet as string using Javascript
I’m developing a Chrome extension, and I’d like users to be able to add their own CSS styles to change the appearance of the extension’s pages (not web pages). I’ve looked into using document.stylesheets, but it seems like it wants the rules to be split up, and won’t let you inject a complete stylesheet. Is there a solution that would