Using pagination, I have a div structure like so in the first page:
<div class="ctema">...</div>
<hr />
<div class="ctema">...</div>
<hr />
<div class="ctema">...</div>
<hr />
But with a jquery script to fetch content via AJAX… the following pages have only:
<div class="ctema">...</div>
<div class="ctema">...</div>
<div class="ctema">...</div>
My goal is to have a HR tag between every div with class=”ctema”… I tried this:
$('.ctematicas').before('<hr />');
But this doesn’t checks if the HR tag is already there or not and after 5 dynamic reloads in the first page I end up with 5 HR in a row …
How can I check if the HR tag is present between classes CTEMA and add one if not present?
Edited: Question clarification.
You can do
or
jQuery’s documentation suggests to prefer the first solution.
Demonstration
If what you really want is to have one hr between the div (and not before the first one), then the solution is even simpler :
Demonstration