Reputation: 337
I'm trying to insert <br/><br/>
after the comment tag <!-- pagebreak -->
but I'm not sure how to achieve this? my code so far:
html:
<div class="tab-content">
some content
<!-- pagebreak -->
some more content
<!-- pagebreak -->
some more content
</div>
jQuery:
$( ".tab-content" )
.contents()
.filter(function() {
return this.nodeType === 8;}
.each().after( "<br/><br/>" ).end());
Can anyone advise on how can achieve this?
Thanks
Upvotes: 0
Views: 97
Reputation: 28564
You were close. You don't need the each
.
$(".tab-content").contents().filter(function() {
return this.nodeType == 8;
}).after("<br><br>")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="tab-content">
some content
<!-- pagebreak -->
some more content
<!-- pagebreak -->
some more content
</div>
Resulting HTML:
<div class="tab-content">
some content
<!-- pagebreak --><br><br>
some more content
<!-- pagebreak --><br><br>
some more content
</div>
Upvotes: 2