javascript-events

Why do registered events disappear when an element is removed from DOM?

This jQuery 1.3.2 code adds an element to the page, registers a "click" event, then removes and reattaches the element: var button = $('<button>Click me!</button>') .click(function(){ alert("Hello") }) .appendTo('body'); $('body').html(''); button.appendTo('body'); The button appears on the page as expected, but clicking on it ...

How to Fire Personal Event in Javascript

I can't fire personal events using Javascript in IE. In Firefox work great. My code is: var evento; if(document.createEventObject) { evento = document.createEventObject(); document.fireEvent('eventoPersonal', evento); } //FF else { evento = document.createEvent('Events'); evento.initEvent('eventoPer...

Adding Javascript EventListener only if no other listener is present?

Hello, I'm a relative tyro in the Javascript programming arena, so please go easy on me. :-) I am trying to add an eventListener to various DOM elements on a page. However, some of the elements I'm adding my event to already have an eventListener, and I don't want to supersede that one; I only want to add my event to an element that ...

What's wrong with this Javascript Code?

I believe something on this code chunk is not properly coded making it incompatible on XHTML 1.0 Transitional. The code snippet collapses div and then on click they will expand. Can somebody see what could be wrong? <script type="text/javascript"> function toggle(div){ el = document.getElementById(div); if (el.style.display == 'n...

keyup Uppercase problem

I would like to have an input that would change to upper case on keyup. So I attach a simple event on keyup. HTML <input id="test"/> Javascript (with jQuery) $("#test").keyup(function(){ this.value = this.value.toUpperCase(); }); But I found that in Chrome and IE, when you push left arrow, the cursor automatically move to end. ...

Will I be able to get a list of registered event handlers on a DOM node inside a firefox extension?

I don't know a thing about implementing extensions in Firefox, but having not seen an extension that does anything like this in the Mozilla's addons page, I don't believe it is possible, but thought I will ask about it anway. ...

Possible to Prevent Enter From Submitting a Form in Javascript From Certain Input Fields Only

I have a form for which onkeyup triggers the creation of a suggestions box for certain fields. I am able to capture the keystrokes for the up arrow, for the down arrow and for escape and use them accordingly to move around in the suggestions box or close it. I would like to use enter to move their selection into the input field that tr...

Javascript behaving weird ,opening an drop/drag item only 'alert' is put

Hi I have Drag/Drop functionality in my page embedded using YAHOO.js which is initalized at load of the page. When 'alert' is put in the init function, the Drag/Drop is working otherwise it is not.Using Firebug I had debugged the code and seen when init function is called but not looping through the function when no alert is put. This fu...

Open Select using Javascript/jQuery?

Hello! Is there a way to open a select box using Javascript (and jQuery)? <select style="width:150px;"> <option value="1">1</option> <option value="2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc arcu nunc, rhoncus ac dignissim at, rhoncus ac tellus.</option> <option value="3">3</option> </select> I have t...

How to read javascript event programatically

Imagine you have a button like this: <input name="myButton" type="button" value="button" onclick="return test();" > where the test functions is as follows: function test(){ // do something return true; // based on some logic return boolean } Now let's say,I don't know what is set for the onclick event, and at runtime I need to ...

Catching the specific javascript code being executed onClick

I am working on a site that has loads of legacy javascript and jquery includes and there is no documentation to show what is happening when. I have a specific problem to fix and I cannot find the relevant code that is being executed when a button is clicked. To save me from trawling through (and making sense of) hundreds of lines of leg...

How do I create a custom event class in Javascript?

How do I create a custom event class similar to ActionScript? What I mean by that is a class that I can use to fire off my own events, send the necessary data. I don't wanna use third-party libraries like YUI or jQuery to do it. My goal is to be able to send a event that looks like this. document.addEventListener("customEvent", eventHa...

Using Javascript to change the method/function an HTML element calls.

I was wondering if its possible to use Javascript to change the function/method that an HTML element calls. Example: <input type="button" id="some_id" name="some_name" value="A Button" onclick="someFunction()" /> I now want to use Javascript to change the method/function called on the onclick event to another function has displayed ...

How can i check if url of current browser tab is changed?

I need it to use in my firefox extension. I already tried window.onload event listener, and check if current url == old url, and it's a good idea, but it does'nt work when page loads pdf. I saw hash changed function too but it works only with ff 3.6; i need it to work at least with ff 3. So, i need an event listener that check if docum...

Speed up web site loading

I am looking for the best way to speed up the load time of my js. The problem is that I am working with a very large site that uses the jquery framework, and what's happening is because the site is also loading, facebook connect, addthis sharing, google analytics and another tracking code, the jquery is delayed a few seconds, and certai...

jQuery hover is not catching all events when mouse is moved rapidly

I have binded jQuery hover to many elements on my page, and when I move mouse rapidly, hove will not catch all events that should be fired. Is there any workaround for this "feature"? ...

Trigger select tag to show options

Im doing my own ajax thing with dropdowns. Ive positioned an imput over a select tag. When stuff is typed into input it collects from db and populates the select menu. Problem is its not noticeable. Is there a way to make the select menu open as if a user has clicked on it? ...

Problem with code for For Loop

Hi, I am doing a project for school and I'm really struggling to understand how to create the code/commands for my for loop in Javascript. Any help would be greatly appreciated. The project is basically this: -There are two arrays: one set of 10 French words another with a set of 10 Engish words. They look like this: var english=new A...

What am I doing wrong on this simple Closure

Hi all, it maybe sleep deprivation but I cannot understand why this isn't working. I want the onclick to return the value of i from a for loop that created the element and applied the event handler. Have put it in a closure and it is still turning the max number of the iterator. window.onload = function(){ var arbitrary_amount = 100; ...

Reliably adding to a Javascript event

I have a radio button, containing an inline onclick event: <input type="radio" class="quantitycheckbox" onclick="alterQuantity(this.form)"> I'm trying to unobtrusively add some more functionality on click, and have this code: function updateCustomFields( box ) { // save current onclick event before assigning new one var currE...