Unusual behavior with: select in .find ()

I am currently updating a site that is currently using jQuery 1.3.2, at least 1.10.2. When I do this, the site chokes on commands like this:

this.form.find(':select[name="fieldtype"]');

      

It shouldn't work - it should be: this.form.find('select[name="fieldtype"]');

- without the colon, but it actually works.

I haven't found anything that ": select ..." suggests. Is it possible that the colon was simply ignored in jQ 1.3.2?

+3


source to share


1 answer


EDIT

I completely forgot about custom pseudo selectors. If, for legacy purposes, you need a newer version of jQuery to handle :select

both select

, you can do this:

jQuery.extend(jQuery.expr[':'], {
    select: function (el) {
        return jQuery(el).is('select');
    }
});

      

And now jQuery(':select')

and jQuery('select')

are equivalent expressions.

Explanation



The error seems to be related to the sizzle

engine css selector used by jquery so that jquery can select dom elements before there document.querySelectorAll

was a thing (or widely available thing). jQuery 1.3.2 uses sizzle 0.9.3 (preview 1!), the next jQuery version 1.4.0 uses sizzle 1.0.0 where the bug is missing.

It seems that the error is that correct tags prefixed with ":" will be interpreted as a tag and not an invalid pseudo

You can check that the culprit is the culprit:

  • Download jquery 1.3.2 and jquery 1.4
  • Copy block sizzle 1.0.0 from 1.4 and replace spike 0.9.3 to 1.3.2

Your version "hybrid 1.3.2" will now reject the selector as well.

+1


source







All Articles