3

So I came across the Next Sibling Selector on the jQuery docs today:

$("label + input")

And was wondering - is there an inverse of this selector? i.e. select the Previous Sibling?

I could use:

$("label + input").prev()

For example in this fiddle, I get all labels in which a label is followed by an input, which is what I want, but is this the only way to do it?

CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
  • 2
    I think it is the simplest one – Arun P Johny Aug 28 '13 at 11:12
  • 1
    label + input selects all the input immediate next to a label. The prev() selects the label preceding an input. Can you please tell me what exactly you are looking at? – Rupam Datta Aug 28 '13 at 11:26
  • @RupamDatta See edit, I want a list of all labels, but only those followed by an input. I assumed that since there was a selector for the forward lookup, there may be one for the inverse. – CodingIntrigue Aug 28 '13 at 13:14

1 Answers1

1

You can use array provided by sibling()

Check this out:

http://api.jquery.com/category/traversing/tree-traversal/

Amin
  • 422
  • 4
  • 4