#8076 closed bug (invalid)
jQuery.live('blur') possible selector issue
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | event | Version: | 1.4.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
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 (3)
comment:1 Changed 12 years ago by
comment:2 follow-up: 3 Changed 12 years ago by
Component: | unfiled → event |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
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 Changed 12 years ago by
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.
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!