Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select anchor tag which are inside of a Paragraph tag?

I want to individually select the first anchor tag and last anchor tag of the <p> tag.

<div class="not01">
  <img src="/assets/images/avatar-mark-webber.webp" alt="Mark Webber image">
  <p> <a href="#">Mark Webber </a> reacted to your recent post <a href="#">My first tournament today!</a></p>
  <span>1m ago</span>
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

By using :first-child and :last:child css selectors.

p a:first-child {
  background-color: yellow;
}

p a:last-child {
  background-color: yellow;
}
<p>
  <a>This anchor is the first child of its parent (p).</a>
  <a>This anchor is the second child of its parent (p).</a>
  <a>This anchor is the third child of its parent (p).</a>
</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading