JSFiddle - React, Tailwind, and code Playground
HTML
<p> 1</p>
<p> 2</p>
<p> 3</p>
<p> 4</p>
<p> 5</p>
<p> 6</p>
<p> 7</p>
JavaScript
$('p').each(function(i) {
var pos = i + 1;
console.log(pos, pos % 3, this)
if (pos % 3 == 0) {
$('<div/>', {
class: 'anuncio',
text: 'Div inserida!'
}).insertAfter(this);
}
});