Benchmark compares QSA & .forEach vs a NodeIterator Now either NodeIterator’s suck or I’m doing it wrong. Question: When should I use a NodeIterator ? In case you don’t know, DOM4 specifies what NodeIterator is. Answer It’s slow for a variety of reasons. Most obviously is the fact …
Tag: javascript
How do I calculate the date in JavaScript three months prior to today?
I Am trying to form a date which is 3 months before the current date. I get the current month by the below code Can you guys provide me the logic to calculate and form a date (an object of the Date data type) considering that when the month is January (1), 3 months before date would be OCtober (10)?
How to perform a Javascript object recursive search that match my needs?
Good day, I am working on a text-based games written in Javascript. I have variable named map that is an associating object containing another object for each rooms. I have found a little algorithm somewhere and I am not sure how to modify it for my specific task. My variable: I would like the function to ret…
Google maps Places API V3 autocomplete – select first option on enter
I have successfuly implemented Google Maps Places V3 autocomplete feature on my input box as per http://web.archive.org/web/20120225114154/http://code.google.com:80/intl/sk-SK/apis/maps/documentation/javascript/places.html. It works nicely, however I would love to know how can I make it select the first optio…
Determine if string is in base64 using JavaScript
I’m using the window.atob(‘string’) function to decode a string from base64 to a string. Now I wonder, is there any way to check that ‘string’ is actually valid base64? I would like to be notified if the string is not base64 so I can perform a different action. Answer If “v…
Get column from a two dimensional array
How can I retrieve a column from a 2-dimensional array and not a single entry? I’m doing this because I want to search for a string in one of the columns only so if there is another way to accomplish this please tell me. I’m using the array defined this way: At the end the size of this array is
Is there an easy way to determine which hemisphere a user is in?
I’m working on a project which includes seasonal content, and we’re thinking of determining the user’s location to work out what season it is for them. The obvious way of doing this is to Geo-locate their IP, then grab the latitude. > 0 is Northern hemisphere, and < 0 is Southern. I…
Get element inside element by class and ID – JavaScript
Alright, I’ve dabbled in JavaScript before, but the most useful thing I’ve written is a CSS style-switcher. So I’m somewhat new to this. Let’s say I have HTML code like this: How would I change Hello world! to Goodbye world!? I know how document.getElementsByClassName and document.getE…
How to disable event links in FullCalendar when using Google Calendar feed?
I am using FullCalendar library to load events in my calendar from Google Calendars. Unfortunately after events have been added to the calendar, they are clickable. When you click on the event you are automatically redirected to the Google Calendars page to view that specific event, or if you have enaught acc…
Converts minutes into days, week, months and years
Let’s suppose I have a number which represents the minutes passed from the start time to now. I wan to create a function which returns the years, months, week and days corresponding to the minutes I am passing to that function. Here an example: What is the best way to achieve the result? Answer Maybe li…