I have the following HTML string
<div class="row">
<div class="col-sm-4">
content
</div>
<div class="col-sm-4">
content
</div>
<div class="col-sm-4">
contnt
</div>
</div>
<div class="row">
<div class="col-sm-4">
content
</div>
<div class="col-sm-4">
content
</div>
</div>
I want to insert
<div class="col-sm-4">content</div>
at the end of the second row (before the closing div tag) so that the second row has three elements.
I tried many things using Jquery for the task, but I am unable to do it. The latest I tried is the following (suppose the long html is stored in HTML, and the to-be-inserted PIECE.
$(HTML).find('.col-sm-4').last().after(PIECE);
Can anyone help me out? There must be a JQuery way for this.
UPDATE: one more thing I forgot to say:
The number of rows is not fixed. I want the PIECE to be inserted into the last row. Note that the long HTML string is NOT part of a page. It is just a string stored in a Javascript variable. I need to insert
class="col-sm-4">content</div>
into it. In my many tests, I find that it is pretty difficult to me.
Thanks!