Bug Tracker

Ticket #8076 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

jQuery.live('blur') possible selector issue

Reported by: tonychu2@… Owned by:
Priority: low Milestone: 1.next
Component: event Version: 1.4.4
Keywords: Cc:
Blocking: Blocked by:

Description

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).val(textVal);
  });
});

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

comment:1 Changed 4 years ago by tonychu2@…

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 follow-up: ↓ 3 Changed 4 years ago by jitter

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to event

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 4 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.