To add class to first child of an element you will use :first selector as follow:
$(selectorname:first).addclass('classname');
For example:
<div class="demo">
<p>hello</p>
<p>hiii</p>
</div>
If you want to add a class to first <p> tag you have to add following script:
$(".demo p:first").addClass('classname');
0 Comment(s)