Skip to content

Check if ‘onload’ would have fired already?

I have a situation where I’d like to set an onload handler for a script element, but it is possible that the script element has already loaded before I do so. If it’s already loaded, I’d like to detect that and run my handler immediately. What would be a reliable way of checking a script ele…

click() method in Firefox

The following code is throwing two alerts as expected in IE but not in Firefox. Please help. Answer Firefox only has a click() function for form elements such as buttons. However, you can call the onClick function directly; you can change the line to This works in firefox or IE (but note that it requires that…

Javascript find if english alphabets only

Am trying to find some text only if it contains english letters and numbers using Javascript/jQuery. Am wondering what is the most efficient way to do this? Since there could be thousands of words, it should be as fast as possible and I don’t want to use regex. Thank you for your time. Answer A regular …

jQuery’s offset() function

I know jQuery does most when it comes to cross-browser issues. I just wanted to know if offset() method of jQuery serves the purpose of cross-browser compatibility, I mean top, left, etc properties that can be derived from it? Basically once I apply top, left, etc properties (which are derived from offset() f…

simplest way to write programs in javascript on desktop?

I’m looking for way to write Javascript programs / scripts on desktop, not inside browser. I want it to run like Python – from the command line, to be able to read files, write files etc. All solutions I find mentioned (Rhino, spidermonkey, V8) are for embedding. Has anyone done simple implementat…

Bitshift in javascript

I’ve got a really big number: 5799218898. And want to shift it right to 13 bits. So, windows-calculator or python gives me: 5799218898 >> 13 | 100010100100001110011111100001 >> 13 70791 | 10001010010000111 As expected. But Javascript: 5799218898 >> 13 | 100010100100001110011111100001 &…

onclick event in the javascript

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 a…