Skip to main content

Bug Tracker

Side navigation

#5252 closed bug (invalid)

Opened September 16, 2009 08:47AM UTC

Closed September 24, 2009 03:18AM UTC

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 (0.5 KB) - added by johnH September 16, 2009 08:47AM UTC.

    Example of attr not working correctly in IE.

Change History (3)

Changed September 16, 2009 06:26PM UTC by justbeez comment:1

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

Changed September 18, 2009 07:01AM UTC by johnH comment:2

That works fine, thanks.

Changed September 24, 2009 03:18AM UTC by dmethvin comment:3

resolution: → invalid
status: newclosed

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