Bug Tracker

Opened 10 years ago

Closed 10 years ago

#5252 closed bug (invalid)

attr adding an event to an input field does not work in IE but does in Firefox

Reported by: johnH Owned by:
Priority: major Milestone: 1.4
Component: unfiled Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:

Description

Using $(":input").attr("onfocus","alert(this.id);"); to add an event action to an input field will work in Firefox but not in IE (version 8.0.6001). Please see attached example.

Attachments (1)

test.html (498 bytes) - added by johnH 10 years ago.
Example of attr not working correctly in IE.

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by johnH

Attachment: test.html added

Example of attr not working correctly in IE.

comment:1 Changed 10 years ago by justbeez

Is there a reason that you would want to do it this way instead of the event methodology in jQuery?

Here's how you should be doing it:

$(":input").focus(function(e) { alert(this.id); });

/* -- OR -- */

$(":input").bind('focus',function(e) { alert(this.id); });

More information is available in the Events section of the documentation: http://docs.jquery.com/Events

comment:2 Changed 10 years ago by johnH

That works fine, thanks.

comment:3 Changed 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

Don't set event handlers using .attr().

Note: See TracTickets for help on using tickets.