Skip to content
Advertisement

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.

Javascript call() & apply() vs bind()?

I already know that apply and call are similar functions which set this (context of a function). The difference is with the way we send the arguments (manual vs array) Question: But when should I use the bind() method ? jsbin Answer I created this comparison between function objects, function calls, call/apply and bind a while ago: .bind allows you

bootstrap datepicker today as default

I am using this bootstrap-datepicker for my datepicker. I’d like the datepicker to choose “today” for start day or default day. I cannot figure out how to set “today” automatically, so I did an inefficient way HTML: JS: Online Sample: http://jsfiddle.net/BXZk2/ Just looking for an easy solution to make the default day as “TODAY”. Thanks Answer This should work: $(“#datepicker”).datepicker(“setDate”,

RGB to XYZ and LAB colours conversion

I’m having problems converting colours from RGB to LAB space It should be straight forward using the formulas from here, only I’m getting back the wrong values RGB = 56,79,132 X = 8.592 Y = 8.099 Z = 22.940 and CIE-L*ab as L* 34.188 a* 8.072 b* -32.478 This is my code; but I can’t see where I’m going wrong.

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 attached, so your options are: Add all the event listeners manually to your cloned node

How to select all other values in an array except the ith element?

I have a function using an array value represented as How can I select all other values in an array except this one? The purpose of this is to reset all other Google Maps images to their original state but highlight a new one by changing the image. Answer Use Array​.prototype​.splice to get an array of elements excluding this one.

setImmediate vs. nextTick

Node.js version 0.10 was released today and introduced setImmediate. The API changes documentation suggests using it when doing recursive nextTick calls. From what MDN says it seems very similar to process.nextTick. When should I use nextTick and when should I use setImmediate? Answer Use setImmediate if you want to queue the function behind whatever I/O event callbacks that are already

Clear input fields on form submit

I know this is continuously asked anew, and I’ve checked out different answers and tried different solutions but to no avail. In some cases it can be really be a case by case thing depending on how the code has been redacted. I’d like to simply have the two input fields in my page to clear when I click submit

TypeScript in combination with BreezeJS

I’m currently working on a project prototype with TypeScript in combination with BreezeJS. I’m using the HotTowel template from John Papa and wrote my own TypeScript ViewModels for each HTML page. To use normal JavaScript libs you need a TypeScript file file.d.ts which is some sort of interface class so TypeScript knows which JavaScript functions there are. With this combination

Advertisement