I am very new to javascript I know that you can add an onclick=”” event to a html element… but is it possible in the javascript itself to declare that when someone clicks on x element an event is triggered? Answer Make sure that you either run this after the element already exists (scripts at the bottom), or when the
Tag: javascript
Changing window.location.href in Firefox in response to an onunload event
I have a strange JavaScript problem using window.location.href, which apparently only affects Firefox (I’m using 3.6). Normally window.location.href would not be read-only, and this works perfectly in Firefox: However, when I call a function in response to an onunload event (<body onunload=”testThis();”>), this doesn’t work as expected: In both cases, the alert displays the current location of the page in
Why doesn’t this Javascript RGB to HSL code work?
I found this RGB to HSL script over at http://www.mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript. I can’t find any other small decent ones. The issue is that this code doesn’t even really work. Would anybody know why? (I don’t know a bit of color math, but maybe it’s returning the complementary?) Edit: when I run rgbToHsl(126,210,22) it’s giving me [ .24, .81, .45 ], which
Waiting for image to load in JavaScript
I’m making an Ajax call which returns me some info including an image path. I prepare all this information in my HTML which will be displayed as a kind of popup. I just toggle the visibility of by popup div from hidden to visible. To set the position of my popup div, I have to calculate depending on the height
jQuery vs. javascript? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 9 years ago. Improve this question I recently stumbled upon some javascript forums (sadly, link is lost somewhere in the universe), where you could feel real hate
Mouse event weirdness
Here is the Greasemonkey script I’m working on (source below): http://userscripts.org/scripts/show/69722 You can test it out on this page: http://forums.whirlpool.net.au/forum/35 Hover over a thread title and a div appears with a preview. The weird thing is, when you move your mouse around on the div, the mouseout event is getting fired for some reason. Anyone have any ideas as to
What is the non-jQuery equivalent of ‘$(document).ready()’?
What is the non-jQuery equivalent of $(document).ready()? Answer This does not answer the question nor does it show any non-jQuery code. See @ sospedra’s answer below. The nice thing about $(document).ready() is that it fires before window.onload. The load function waits until everything is loaded, including external assets and images. $(document).ready, however, fires when the DOM tree is complete and
Browser-independant workaround for onload event — making sense?
I have recently found myself playing around with events, and as there is no standard for the event indicating that a page has been loaded (like onload vs. pageshow) I wondered whether something speaks against simply putting some JavaScript at the end of the page. This code would then be executed when the page is loaded. In this example I
Detect a finger swipe through JavaScript on the iPhone and Android
How can you detect that a user swiped his finger in some direction over a web page with JavaScript? I was wondering if there was one solution that would work for websites on both the iPhone and an Android phone. Answer Simple vanilla JS code sample: Tested in Android.
Testing if jQueryUI has loaded
I’m trying to debug a website, and I think that jQueryUI may not have loaded properly. How can I test if jQueryUI has loaded? Answer OR Should do the trick