jQuery first of type selector?

后端 未结 6 2038
独厮守ぢ
独厮守ぢ 2021-01-03 18:35

How would I select the first

element in the following

with jQuery?

heading

6条回答
  •  忘掉有多难
    2021-01-03 19:33

    You almost know the answer (from your post title). There is a selector in jQuery called :first-of-type. Use it to find and add class to the first p tag automatically, like so:

    $("div p:first-of-type").addClass('someClass');
    

提交回复
热议问题