I’m trying to create a function which will add an overlay to a thumbnail image when you hover over it and remove the overlay when you leave it. Here is my HTML… And here is my jQuery… The trouble is that when the overlay is created the mouse is already over it and that triggers the “mouseout” of the container,
How to create a tag with Javascript?
I’m looking for a way to insert a <style> tag into an HTML page with JavaScript. The best way I found so far: This works in Firefox, Opera and Internet Explorer but not in Google Chrome. Also it’s a bit ugly with the <br> in front for IE. Does anyone know of a way to create a <style> tag that
Seeding the random number generator in Javascript
Is it possible to seed the random number generator (Math.random) in JavaScript? Answer No, it is not possible to seed Math.random(), but it’s fairly easy to write your own generator, or better yet, use an existing one. Check out: this related question. Also, see David Bau’s blog for more information on seeding.
Cross-browser way to determine whether a DOM event was cancelled
Is there a cross-browser way from a Javascript event handler to determine whether the event has been cancelled by a previous handler? IE and other browsers like Chrome etc. have an event.returnValue property that can be tested, but FireFox doesn’t appear to have any such property. Here’s an example of the scenario I’m talking about. You have a form like
What is the scope of variables in JavaScript?
What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally? Answer TLDR JavaScript has lexical (also called static) scoping and closures. This means you can tell the scope of an identifier by looking
jQuery – setting the selected value of a select control via its text description
I have a select control, and in a javascript variable I have a text string. Using jQuery I want to set the selected element of the select control to be the item with the text description I have (as opposed to the value, which I don’t have). I know setting it by value is pretty trivial. e.g. But I’m a
Compare two dates with JavaScript
Can someone suggest a way to compare the values of two dates greater than, less than, and not in the past using JavaScript? The values will be coming from text boxes. Answer The Date object will do what you want – construct one for each date, then compare them using the >, <, <= or >=. The ==, !=, ===,
How to check if element is visible after scrolling?
I’m loading elements via AJAX. Some of them are only visible if you scroll down the page. Is there any way I can know if an element is now in the visible part of the page? Answer This should do the trick: Simple Utility Function This will allow you to call a utility function that accepts the element you’re looking
Possible to flash a Browser window using Javascript?
Like many programs flash their window on the taskbar / dock to alert the user to switch to the program, Is it possible to flash the Browser window using Javascript? (FireFox-only scripts are also welcome) This is useful for web-based Chat / Forum / Community-based software where there is lots of real-time activity. Answer @Hexagon Theory: Why would you ever
With JavaScript, can I change the Z index/layer of an SVG element?
Let’s say I have a couple composite shapes (<g>). I want to be able to click and drag them, but I want the one I happen to be dragging at the moment to be on TOP of the other one in the Z order, so that if I drag it over the OTHER one, the other one should be eclipsed.