Creating and handling JavaScript events inline in HTML or through a script.
723
votes
8answers
173k views
event.preventDefault() vs. return false
When I want to prevent other event handlers from executing after a certain event is fired, I can use one of two techniques. I'll use jQuery in the examples, but this applies to plain-JS as well:
#1 ...
217
votes
12answers
142k views
On - window.location.hash - change?
I am using Ajax and hash for navigation. Is there a way to check if the window.location.hash changed like this?
http://example.com/blah#123 to http://example.com/blah#456
It works if I check it when ...
213
votes
9answers
97k views
How to distinguish between left and right mouse click with jQuery
What is the way of obtaining the clicked mouse button with JavaScript using jQuery?
$('div').bind('click', function(){
alert('clicked');
});
this is triggered by both right and left click, what ...
200
votes
4answers
107k views
53
votes
8answers
49k views
Simulate JavaScript Key Events
Is it possible to simulate key press events programatically in JavaScript?
234
votes
14answers
78k views
jQuery $(document).ready and UpdatePanels?
I'm using jQuery to wire up some mouseover effects on elements that are inside an UpdatePanel. The events are bound in $(document).ready . For example:
$(function() {
...
356
votes
15answers
146k views
How to debug Javascript/jQuery event bindings with FireBug (or similar tool)
I need to debug a web application that uses jQuery to do some fairly complex and messy DOM manipulation. At one point, some of the events that were bound to particular elements, are not fired and ...
59
votes
4answers
57k views
How to trigger event in JavaScript
I have attached an event to a text box using addEventListener. It works fine. My problem arouse when I wanted to trigger the event programmatically from another function.
How can I do it?
172
votes
14answers
119k views
Using jQuery to test if an input has focus
On the front page of a site I am building, several <div>s use the CSS :hover property to add a border when the mouse is over them. One of the <div>s contains a <form> which, using ...
32
votes
2answers
38k views
How to simulate mouse click using Javascript?
I am know about the document.form.button.click() method. However, I'd like to know how to simulate the onclick event.
I found this code somewhere here in StackOverflow, but I don't know how to use it ...
37
votes
5answers
22k views
Javascript Object.Watch for all browsers?
Hey all, I was looking for an easy way to monitor an object or variable for changes, and I found Object.Watch that's supported in Mozilla browsers, but not IE. So I started searching around to see if ...
22
votes
6answers
39k views
javascript domready?
I know I can use different frameworks like prototype or jquery to attach a function to the window.onload, but's not what I'm looking for.
I need something like .readyState so that I can do something ...
76
votes
8answers
28k views
Listening for variable changes in JavaScript or jQuery
Is it possible to have an event that fires when the value of a certain variable changes?
Thanks!
31
votes
3answers
13k views
How to find out which JavaScript events fired?
I have a select list:
<select id="filter">
<option value="Open" selected="selected">Open</option>
<option value="Closed">Closed</option>
</select>
When I ...
16
votes
3answers
9k views
How does a function in a loop (which returns another function) work?
I've been trying to assign a function to onclick event of a dynamically created "a" tag in JavaScript. All of the tags are created in a loop as follows:
for ( var i = 0; i < 4; i++ )
{
var a = ...