Load html only 1 time after 3° paragraph of jquery text?

Asked

Viewed 17 times

-3

I have this example but I would like you not to repeat, I would like you to appear only once!

$('p').each(function(i) {
  var pos = i + 1;
  console.log(pos, pos % 3, this)
  if (pos % 3 == 0) {
    $('<div/>', {
      class: 'anuncio',
      html: '<div id="phtur">Div inserida!</div>'
    }).insertAfter(this);
  }
});

    $('#phtur').hide().delay(10000).slideToggle('slow');
    $('#phtur').click(function(){
        $("#phtur").slideToggle('slow');
  
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<p>&nbsp;1</p>
<p>&nbsp;2</p>
<p>&nbsp;3</p>
<p>&nbsp;4</p>
<p>&nbsp;5</p>
<p>&nbsp;6</p>
<p>&nbsp;7</p>

1 answer

-1


Change:

if (pos % 3 == 0)

for

if (pos == 0)

Would solve your problem

  • 1

    Thanks, it worked out! OBG

Browser other questions tagged

You are not signed in. Login or sign up in order to post.