Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Small change to avoid over-specifying the related field selector... #22

Closed
wants to merge 1 commit into from

3 participants

Matt Hinchliffe Jordan Harband Sven Franck
Matt Hinchliffe

... Overcompensating for such a user error is not worth the performance hit (in my experience).

I have setup a basic JSPerf test to demonstrate the difference http://jsperf.com/over-qualified-selector-performance

Matt Hinchliffe i-like-robots Small change to avoid over-specifying the related field selector. Ove…
…rcompensating for such a user error is not worth the performance hit (in my experience).
92326bd
Jordan Harband

Seems like you can cover the same use case by changing line 134 to $field = $("#" + for_attr + ':input'); or `$field = $("#" + for_attr).filter(':input');

Sven Franck

@i-like-robots

I just tried your commit and it produces an error on iPad. I assume this.for and this.htmlFor are not supported, because once I revert to the original attr('for') it's working again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 16, 2011
  1. Matt Hinchliffe

    Small change to avoid over-specifying the related field selector. Ove…

    i-like-robots authored
    …rcompensating for such a user error is not worth the performance hit (in my experience).
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 10 deletions.
  1. +2 −10 src/jquery.infieldlabel.js
12 src/jquery.infieldlabel.js
View
@@ -125,21 +125,13 @@
// Find input or textarea based on for= attribute
// The for attribute on the label must contain the ID
// of the input or textarea element
- var for_attr = $(this).attr('for'), $field;
+ var for_attr = this.for || this.htmlFor, $field;
if (!for_attr) {
return; // Nothing to attach, since the for field wasn't used
}
// Find the referenced input or textarea element
- $field = $(
- "input#" + for_attr + "[type='text']," +
- "input#" + for_attr + "[type='search']," +
- "input#" + for_attr + "[type='tel']," +
- "input#" + for_attr + "[type='url']," +
- "input#" + for_attr + "[type='email']," +
- "input#" + for_attr + "[type='password']," +
- "textarea#" + for_attr
- );
+ $field = $("#" + for_attr);
if ($field.length === 0) {
return; // Again, nothing to attach
Something went wrong with that request. Please try again.