Selector –> :first used to select the first element.

Now suppose you want to select first p element on the page, then jQuery provides a very useful and powerful selector called ":first" that selects the first element. Its usage can be described as follows:


The above syntax selects the first p element of our page. Now let us look at the short example:

<!--program starts-->


<script type='text/javascript'>
$("p:first").css("font-size","20px"); //makes the first p tag contents' size 20px
$("p:first").css("color","#f11"); //makes the text color "red"

<p>See only first p tag is affected</p>
<p>These p tags are not affected</p>

<!--program ends-->

So the above program changes the color of content or text of first p tag into "red" with size "20px".
It only affects the first p tag of our page and have no effect on other p tags of our page.

0 0 votes
Article Rating
Notify of

1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
7 years ago

nice jquery article