sizzle

Is it possible to create custom jQuery selectors that navigate ancestors? e.g. a :closest or :parents selector

╄→尐↘猪︶ㄣ 提交于 2019-12-29 03:37:09
问题 I write a lot of jQuery plugins and have custom jQuery selectors I use all the time like :focusable and :closeto to provide commonly used filters. e.g. :focusable looks like this jQuery.extend(jQuery.expr[':'], { focusable: function (el, index, selector) { return $(el).is('a, button, :input[type!=hidden], [tabindex]'); }; }); and is used like any other selector: $(':focusable').css('color', 'red'); // color all focusable elements red I notice none of the jQuery selectors available can

What's the use of Array.prototype.slice.call(array, 0)?

喜夏-厌秋 提交于 2019-12-28 07:39:30
问题 I was just browsing Sizzle's source code and I came across this line of code: array = Array.prototype.slice.call( array, 0 ); I looked up what the function is, but I came to the conclusion that it just returns all elements of the array starting from index 0, and puts the whole into the array, i.e. it doesn't really do anything at all. What is therefore the use of this line of code? What am I missing? Edit: It's line 863 from https://github.com/jquery/sizzle/blob/master/sizzle.js#L863. 回答1:

Javascript find pseudo elements

♀尐吖头ヾ 提交于 2019-12-23 10:08:31
问题 So I've been work on a CSS selector engine, and I want to support pseudo-elements (::before, ::after, ::selection, ::first-line, etc). I noticed Slick, Sizzle, and some other popular engines seem to support them, but when looking through their code I found no code for it (now granted, I didn't look that hard). Does anyone know how they do it or some way I could do it? 回答1: Here's a simple way to find them in Webkit using jQuery, can fairly easily be converted to standard JS: $('*').filter

Is there a JQuery DOM manipulator/CSS selector equivalent class in PHP?

爱⌒轻易说出口 提交于 2019-12-21 21:38:58
问题 I know that I can use DOMDocument and DOMXPath to manipulate XML files. But, I really love JQuery, and it would be great if there was something more like JQuery in the PHP world that I could use for sever side DOM manipulation. NOTE: I'm only interested here in how JQuery Selects and Manipulates the DOM, not all the other parts of JQuery (I guess you can say just the Pop and the Sizzle parts). Update: It looks like there is an equivalent for the selector functions, but as far as the

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

 ̄綄美尐妖づ 提交于 2019-12-19 17:36:18
问题 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)

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

百般思念 提交于 2019-12-18 12:27:08
问题 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

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

谁说胖子不能爱 提交于 2019-12-17 21:44:07
问题 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? 回答1: 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

CSS parser/abstracter? How to convert stylesheet into object

我怕爱的太早我们不能终老 提交于 2019-12-17 16:25:17
问题 Is there a standard or reliable method already out there for a javascript framework such as jquery to parse a stylesheet into an object? Two reasons for why I'm wondering: I have seen a couple of questions where someone wanted to know how to get the style attribute that was set by the stylesheet for a selector, not what the selector eventually inherited. If Sizzle does what it is supposed to, this could be a solution for making sure a stylesheet got rendered correctly cross-browser. Basically

Reverse Zen Coding

给你一囗甜甜゛ 提交于 2019-12-13 14:12:52
问题 I'm writing a javascript unit test suite and one of the features I'd like to add is the ability to assert that a certain element and its children match a given HTML structure. My first idea is to use jQuery (well, Sizzle) and ask that users write Zen Code statements to make assertions. My first question is "Has this been done before? Can I steal it?" . If not, is there a specification printed anywhere for how to parse a Zen Code statement? Are there any shortcuts I could make, given the power

Very weird Chrome behavior in an open (focused) “select” element

一世执手 提交于 2019-12-12 16:07:56
问题 Here's a <select> element: <select> <option>Hello</option> <option>Banana</option> <option>Balloon</option> <option>Something</option> <option>Potato</option> <option>Cleveland</option> </select> Here's a little bit of JavaScript (a jQuery "ready" handler): $(function() { function foo() { var s = $('select').find(':selected'); } setInterval(foo, 200); }); Here is the jsfiddle for this question.. The handler sets up an interval timer which, every 200 milliseconds, finds the currently-selected