Home > Net >  InsertAfter after certain amount of elements
InsertAfter after certain amount of elements

Time:11-17

Is it possible to insert html after a certain amount of elements with javascript, as example:

<content>
  <article class=“art”>Some content 1</article>
  <article class=“art”>Some content 2</article>
  <article class=“art”>Some content 3</article>
  <article class=“art”>Some content 4</article>
</content>

I’d like to insert some html after the 3rd article.

CodePudding user response:

$("article:nth-of-type(3)").append("what you like"); 

its for jquery in fact for javascript:

var thirdElement = document.querySelector(".art article:nth-of-type(3)")
thirdElement.append("what you like to append")
  • Related