I’m running a relatively simple function (update a span’s innerHTML) on mousemove. The application is a Leaflet map. When the mouse is moving, there is palpable lag when zooming, panning and loading tiles. I only need to update the span about 10-20 times per second at most. (See here for the page …
Tag: javascript
How to get first date and last date of the week from week number and year?
In JavaScript I want to get first date of the week and last date of the week by week number and year only. For example if I my input is: 2(week),2012 Then my output should be: 2012-01-08 and 2012-01-14 Answer Try this: n1 contains the first day of the week n2 contains the last day of the week As for
jQuery hide dropdown when clicked anywhere but menu
I’m trying to make it so that my dropdown menu shows when you click a button, and hides when you click anywhere except the dropdown menu. I have some code working, as far as not closing when you click the menu, however when you click the document when the menu is closed, it shows the menu, so it continu…
In JavaScript e.target is not working as I expected
I have written some JavaScript that opens an element when an element is clicked. However I can’t get the: This is not working to how I want it because: You can open more than one of the showed elements when I only want one open at a time. When I click inside the element it closes, I only want it
Calculating the maximum value for a decimal using scale and precision
I am working on a JavaScript function that takes two values: precision of a decimal value & scale of a decimal value. This function should calculate the maximum value that can be stored in a decimal of that size. For example: a decimal with a precision of 5 and a scale of 3 would have a maximum value of 9…
Is there any way to rename js object keys using underscore.js
I need to convert a js object to another object for passing onto a server post where the names of the keys differ for example needs to turn into where I have lookup obj available for mapping all the keys Is there a function available in underscore.js or jQuery that I can use that does this functionality? than…
How to parse link header from github API
the github API sends the pagination data for the json results in the http link header: since the github API is not the only API using this method (i think) i wanted to ask if someone has a useful little snippet to parse the link header (and convert it to an array for example) so that i can use it
how to get all parent nodes of given element in pure javascript?
I mean an array of them. That is a chain from top HTML to destination element including the element itself. for example for element <A> it would be: Answer A little shorter (and safer, since target may not be found):
How to fire event s in a dynamically generated List in jQuery
I have created a list dynamically using JavaScript and I want to invoke click event as go in normally HTML generated list. This is what I have tried so far but I could not fire a single event. Can any one help? Answer Try: $(‘.addnew’).delegate(‘li’, ‘click’, function () { …
JavaScript strings – UTF-16 vs UCS-2?
I’ve read in some places that JavaScript strings are UTF-16, and in other places they’re UCS-2. I did some searching around to try to figure out the difference and found this: Q: What is the difference between UCS-2 and UTF-16? A: UCS-2 is obsolete terminology which refers to a Unicode implementat…