I have an element in the DOM d
in a jQuery object and I'd like to count the number of elements matching font[color=#ff6600]
before the element. Is there a CSS selector I can use for this?
views:
34answers:
4Nah, I'd like to include things other than direct siblings, just as long as they appear later in the DOM.
Andrey Fedorov
2010-08-24 04:02:42
(that is, siblings+their descendants, of the element, and also of its ancestors)
Andrey Fedorov
2010-08-24 04:03:34
A:
I would look at the selectors .siblings() and .parents() along with .context to meet this specific requirement.
Floyd Pink
2010-08-24 04:01:31
A:
Your question is imprecise so this is my best guess
$(d).prevAll('font[color=#ff6600]').length
If you mean to collect all font[color=]
elements that appear lexically before d
then you can't do this with a pure selector. you'll need to iterate over a larger matching set
Scott Evernden
2010-08-24 04:07:30
I think this is very close, but I need to search the siblings' descendants, as well as the siblings and descendants of all ancestors of `d`.
Andrey Fedorov
2010-08-24 04:10:58
+1
A:
I think this is what I was looking for. Will test thoroughly in a bit:
$(d).parents().andSelf().prevAll().find('font[color=#ff6600]')
Andrey Fedorov
2010-08-24 04:38:45