jquery .before() if class isn't present
Posted
by
Afonso Gomes
on Stack Overflow
See other posts from Stack Overflow
or by Afonso Gomes
Published on 2012-10-25T10:23:43Z
Indexed on
2012/10/25
11:01 UTC
Read the original article
Hit count: 193
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>
I tried this:
$('.ctematicas').before('<hr />');
But this doesn't checks if the HR tag is there or not and after 5 dynamic reloads In the first page I have 5 HR in a row ...
How can I check if the HR tag is present between classes CTEMA and add one if not present?
© Stack Overflow or respective owner