Return PyQuery of only the element with the provided index:: >>> d = PyQuery(' Hi Bye ') >>> d('p').eq(0) [ ] >>> d('p').eq(1) [ ] >>> d('p').eq(2) [] ..
(self, index)
| 671 | return self._copy(elements, parent=self) |
| 672 | |
| 673 | def eq(self, index): |
| 674 | """Return PyQuery of only the element with the provided index:: |
| 675 | |
| 676 | >>> d = PyQuery('<p class="hello">Hi</p><p>Bye</p><div></div>') |
| 677 | >>> d('p').eq(0) |
| 678 | [<p.hello>] |
| 679 | >>> d('p').eq(1) |
| 680 | [<p>] |
| 681 | >>> d('p').eq(2) |
| 682 | [] |
| 683 | |
| 684 | .. |
| 685 | """ |
| 686 | # Slicing will return empty list when index=-1 |
| 687 | # we should handle out of bound by ourselves |
| 688 | try: |
| 689 | items = self[index] |
| 690 | except IndexError: |
| 691 | items = [] |
| 692 | return self._copy(items, parent=self) |
| 693 | |
| 694 | def each(self, func): |
| 695 | """apply func on each nodes |