Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#8076 closed bug (invalid)

jQuery.live('blur') possible selector issue

Reported by: [email protected] Owned by:
Priority: low Milestone: 1.next
Component: event Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:


The following code trims all textboxes (including dynamic ones) on blur:

$(function() {
  // Auto-trim all textboxes on blur
  $("input:text,").not(":disabled").live("blur", function () {
    var textVal = $.trim($(this).val()); // trim the value

This code does not work without the extra comma in the selector "input:text,". I've tried it in IE8 and FF3.6. The selector "without comma" works when not using ".live()", but then it won't apply to dynamic textboxes...

Change History (3)

comment:1 Changed 12 years ago by [email protected]

The test code is here: http://jsfiddle.net/e7rey/1/

By the way, I discovered that when I removed the not(":disabled") part from the selectors, it also worked without the comma!

comment:2 Changed 12 years ago by jitter

Component: unfiledevent
Priority: undecidedlow
Resolution: invalid
Status: newclosed

Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case!

This isn't a bug. The live documentation states:

DOM traversal methods are not supported for finding elements to send to .live(). Rather, the .live() method should always be called directly after a selector, as in the example above.

This directly applies to your test case. You could do $("input:text:not(:disabled)").live(...) instead which should work

comment:3 in reply to:  2 Changed 12 years ago by anonymous

Thank you jitter for the clear explanation. Sorry about the false alarm. When I read the documentation before I did not understand what DOM traversal methods were. I do now :) Thanks again.

Note: See TracTickets for help on using tickets.