开发者

Counting elements matching pattern before a point in the DOM

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?


I think this is what I was looking for. Will test thoroughly in a bit:

$(d).parents().andSelf().prevAll().find('font[color=#ff6600]')


.nextAll() maybe?

http://api.jquery.com/nextAll/


I would look at the selectors .siblings() and .parents() along with .context to meet this specific requirement.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜