sizzle

IE Javascript error “Object doesn't support this property or method” within jQuery

与世无争的帅哥 提交于 2019-12-01 16:51:36
For some reason, I am getting the following Javascript error in Internet Explorer 8 on line 3156 of jquery.js (version 1.4.3, non-compressed version): Object doesn't support this property or method . No error occurs in Firefox and Google Chrome. This is the line the error occurs on: if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { Investigation ( console.log(Expr.leftMatch[type]) ) produces the following interesting result: In Google Chrome, it outputs /(^(?:.|\r|\n)*?):((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\3\))?(?![^\[]*\])(?![^\(]*\))/

How do I extend jQuery's selector engine to warn me when a selector is not found?

这一生的挚爱 提交于 2019-12-01 11:59:55
Say I make a mistake when I'm trying to find an element and I make a typo, like $('lsdkfj') . Instead of jQuery returning me an empty array, I'd like to return an error message in the console, like "The selector 'lsdkfj' cannot be found" . What is the best way to go about doing this? Like this: var oldInit = $.fn.init; $.fn.init = function(selector, context, rootjQuery) { var result = new oldInit(selector, context, rootjQuery); if (result.length === 0) console.info("jQuery call has no elements!", arguments); return result; }; 来源: https://stackoverflow.com/questions/5744997/how-do-i-extend

How do I extend jQuery's selector engine to warn me when a selector is not found?

巧了我就是萌 提交于 2019-12-01 10:08:35
问题 Say I make a mistake when I'm trying to find an element and I make a typo, like $('lsdkfj') . Instead of jQuery returning me an empty array, I'd like to return an error message in the console, like "The selector 'lsdkfj' cannot be found" . What is the best way to go about doing this? 回答1: Like this: var oldInit = $.fn.init; $.fn.init = function(selector, context, rootjQuery) { var result = new oldInit(selector, context, rootjQuery); if (result.length === 0) console.info("jQuery call has no

Is there an alternative to jQuery / sizzle that supports textNodes as first class citizens in selectors?

一笑奈何 提交于 2019-12-01 07:28:31
问题 I've discovered that I have a need for selectors with full support for DOM textNode s that jQuery doesn't provide. jQuery ignores text nodes, probably because most pages have tons of irrelevant blank ones between tags that the various browsers can treat differently. Most answers to jQuery questions about text nodes come down to using the .contents() function which returns all the child nodes for the selected items, including text nodes - all other jQuery APIs ignore text nodes. Often you don

How to get a specific jQuery item from a list of items?

别等时光非礼了梦想. 提交于 2019-12-01 03:05:35
I have this: <ul> <li>first</li> <li>second</li> <li>third</li> <li>fourth</li> </ul> Then I select it all with jQuery: $('ul').find('li'); or $('ul li'); How can I, from those two jQuery selectors get the, for instance only second li, or third, and to leave first and fourt alone? I thought it might work with: $('myselector').get(indexNumber); // however, it won't work. Any ideas for this issue? Thanks. The get method returns the DOM element, so then you would have to wrap it inside a new jQuery object. You can use the eq method: var j = $('ul li').eq(1); // gets the second list item Use :eq()

How to get a specific jQuery item from a list of items?

拥有回忆 提交于 2019-11-30 22:21:28
问题 I have this: <ul> <li>first</li> <li>second</li> <li>third</li> <li>fourth</li> </ul> Then I select it all with jQuery: $('ul').find('li'); or $('ul li'); How can I, from those two jQuery selectors get the, for instance only second li, or third, and to leave first and fourt alone? I thought it might work with: $('myselector').get(indexNumber); // however, it won't work. Any ideas for this issue? Thanks. 回答1: The get method returns the DOM element, so then you would have to wrap it inside a

jQuery: subtle difference between .has() and :has()

旧时模样 提交于 2019-11-30 07:06:23
When used with the child selector > , the two variants of jQuery's "has" behave differently. Take this HTML: <div> <span>Text</span> </div> Now: $("div:has(>span)"); would return it, while: $("div").has(">span"); would not. Is it a bug or a feature? Compare here: http://jsfiddle.net/aC9dP/ EDIT: This may be a bug or at least undocumented inconsistent behavior. Anyway, I think it would be beneficial to have the child selector consistently work as an unary operator. It enables you to do something that otherwise would require a custom filter function — it lets you directly select elements that

Method for selecting elements in Sizzle using fully-qualified URLs

Deadly 提交于 2019-11-29 15:02:50
While working on a script recently, I came across a peculiar nuance of how Sizzle works with the href attribute . Specifically, using an attribute selector on an href , Sizzle will use the actual attribute value: // Will not find <a href="index.html">... $('a[href="http://www.example.com/index.html"]') Sizzle uses .getAttribute() instead of elem.href (or more precisely, elem['href'] , as Sizzle does in most cases ); elem.href would provide the fully-qualified URL. To understand this a bit more, I created a fiddle to try different forms of URLs . In the process of testing, I discovered the

How is the jQuery selector $('#foo a') evaluated?

孤街浪徒 提交于 2019-11-28 16:12:01
As a example of jQuery code ( https://coderwall.com/p/7uchvg ), I read that the expression $('#foo a'); behaves like this: Find every a in the page and then filter a inside #foo . And it does not look efficient. Is that correct? And if yes, how should we do that in a better way? That is correct - Sizzle (jQuery's selector engine) behaves the same way as CSS selectors . CSS and Sizzle selectors are evaluated right-to-left , and so #foo a will find all a nodes, then filter those by nodes that descend from #foo . You improve this by ensuring that your leaf selectors have a high specificity,

Wildcards in HTML5 data attributes

▼魔方 西西 提交于 2019-11-28 13:49:48
Is it possible to find all DOM elements with jQuery with wildcards in the attribute name? Consider the following HTML: <input id="val1" type="text" data-validate-required data-validate-minlength="3" data-validate-email /> What I am trying to achieve is to find all dom nodes with an attribute name starting with data-validate- As far as I understand the wildcards described here are concerned with "value" of the attribute. The reason for this is - I want to find out which elements should be validated at all - and afterwards find out which validation parameters (like -email) comes in play. Thanks