Skip to content
Advertisement

Tag: javascript

window.onload vs $(document).ready()

What are the differences between JavaScript’s window.onload and jQuery’s $(document).ready() method? Answer The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded. The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the

Remove key press delay in Javascript

I have the following problem: I’m trying to write a Javascript game, and the character is being controlled by the arrow keys. The problem is, when one keeps the key pressed, there is a short delay between firing the first keypress and the repeated keypress. Also, when one presses the “right arrow key” and keeps it pressed, and then presses

Incrementing a date in JavaScript

I need to increment a date value by one day in JavaScript. For example, I have a date value 2010-09-11 and I need to store the date of the next day in a JavaScript variable. How can I increment a date by a day? Answer Three options for you: 1. Using just JavaScript’s Date object (no libraries): My previous answer

IE6 Covering Div

I have a Google Map on one web page where I want to disable both scrolling and zooming. I accomplish this by having an empty DIV element with absolute positioning cover the map area. Firefox/Chrome work fine, but IE6 doesn’t really care about this DIV. For some reason, it just lets me drag the map. I set the DIVs background

How do I include – and ‘ in this regular expressions?

I have a this regular expression below for some input name fields. How do I include an apostrophe and a hyphen in this? Answer Hyphen is already included (twice), you can add the apostrophe by just editing it into the character class: You can rewrite it to look like this, so that there’s no need to escape the hyphen and

How do I check if file exists in jQuery or pure JavaScript?

How do I check if a file on my server exists in jQuery or pure JavaScript? Answer With jQuery: EDIT: Here is the code for checking 404 status, without using jQuery Small changes and it could check for status HTTP status code 200 (success), instead. EDIT 2: Since sync XMLHttpRequest is deprecated, you can add a utility method like this

Preloading images with JavaScript

Is the function I wrote below enough to preload images in most, if not all, browsers commonly used today? I have an array of image URLs that I loop over and call the preloadImage function for each URL. Answer Yes. This should work on all major browsers.

Advertisement