Answer the question
In order to leave comments, you need to log in
Parse Jquery selector with custom pointers?
Good day.
Maybe I'm reinventing the wheel. If so, please point me to the right path.
The essence of the problem: There is a Jquery selector, but not a standard one, but supplemented with certain things so that you can select attribute values, for example:
div.border_premium [email protected]
I use the function to turn it into a query of the form
$('div.border_premium a').each(function(){<br>
var return = $(this).attr('href');<br>
});<br>
if (path.match(/'@"/i)) {<br>
var path=....<br>
}<br>
div.listItem|table tr td:eq(0)~contents().eq(0).text()
- in the transformed form should become$('div.listItem').find('table tr td:eq(0)').each(function (){<br>
var return = $(this).contents().eq(0).text();<br>
});<br>
Answer the question
In order to leave comments, you need to log in
I wouldn't do that at all - you're putting custom logic on top of "standard" jQuery selectors, filling your code with untold risks. How will the next / new developer deal with all this? What will you do if something is changed/added in Sizzle and it breaks everything for you?
But everything, probably, depends on tasks.
If you need to select certain attributes of a collection of elements, write a wrapper, something like
function collectAttributes(collection, attribute){
// тут собираете запрашиваемые атрибуты и возвращаете новую коллекцию
}
$('div.listItem').find('table tr td:eq(0)').each(function (){
var return = $(this).contents().eq(0).text();
});
div.listItem|table tr td:eq(0)~contents().eq(0).text()
. $.fn.extend({
/*
* 4-10 times faster .each replacement
*/
each2 : function (c) {
var j = $([0]), i = -1, l = this.length;
while (
++i < l
&& (j.context = j[0] = this[i])
&& c.call(j[0], i, j) !== false //"this"=DOM, i=index, j=jQuery object
);
return this;
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question