My code splits the text and place a html code after a certain number of words. It's working, the problem is that the split function not only splits text, but also splits HTML. How can I configure it to split text only? Let's say I have an article and I need a banner to appear in the middle of the article, if I don't take care, I'll split some div or something like that.
Here's the code:
<script type="text/javascript">
jQuery(function($) {
var wordList = $(".newsitem_text").html().split(' ');
var newHtml = '';
$.each(wordList, function(index, word){
newHtml += ' ' + word;
if (index == 10) {
newHtml += 'Some HTML goes here'
}
})
;
$(".newsitem_text").html(newHtml);
});
</script>