How to select the first, second, or third element with a given class name?

后端 未结 7 2219

How can I select a certain element in a list of elements? I have the following:

my text
7条回答
  •  遥遥无期
    2020-11-27 15:04

    You probably finally realized this between posting this question and today, but the very nature of selectors makes it impossible to navigate through hierarchically unrelated HTML elements.

    Or, to put it simply, since you said in your comment that

    there are no uniform parent containers

    ... it's just not possible with selectors alone, without modifying the markup in some way as shown by the other answers.

    You have to use the jQuery .eq() solution.

提交回复
热议问题