Quite an interesting challenge for me was, i have a div
block which contains text(content which can contain different number of any elements like <p> <ul> <div>
etc, its like edited Article). This Article have been posted already on my site, and i have added another div
block which appers after this Article is loaded. What i need is to put this block at the end of Article and this block should wrap text around Article like on image below. At the moment "Also related to this article" - its a block which i want to insert.
Ofcourse i can just append this block before the last <p>
element, but last element may be <ul>
or another small <div>
or <span>
, i have different articles, which user can post.
What i think is to get the length of my Article div
and subtracted from the current length of the number of characters that will suit me and insert related article <div>
there.
So, for examle(Article text is much bigger, but this is just simple):
<div id="article">
Lorem Ipsum is simply dummy text of the printing and typesetting industry
<p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
</div>
<div id="related_article">
<ul>
<li> Item1</li>
<li> Item2</li>
<li> Item3</li>
</ul>
</div>
Jquery code:
$(document).ready(function() {
var text_length = $.trim($("#article").text()).length;
var length_before = 30;//for example
var related = $('div#related_article');
var content = $('div#article');
var substract = text_length - length_before;
//is it possible to put this *related* div
//into substract point in content at the end of it.
});
Should i use regex? or is it possible to do like this somehow? maybe i just stupid and miss something, please show me the way of action
.
english is not my native, so there might be syntax errors
As people asked i provide an example of how can Article looks like
Here is an example of how can looks like my article it can contain a lot of tags