I have been through:
- Wrap plain text in paragraph Jquery
- Wrap text within element
- Wrap element between two elements in JavaScript/jQuery?
- jQuery wrapAll contents including text between two tags
- Get the text after span element using jquery none of those provide a solution for what I am trying to do. I think adding the div may be part of the reason.
How can I enclose the content between div_1 and div_2 in a div_3
<div id="div_1"></div>
<strong>stuff here that always begins with same string but does not end that way</strong>
some unknown text here
<div id="div_2"></div>
The real issue is that it seems you cannot insert the beginning of a div without the end of div showing up automatically.
For example, if I do something like this:
$(document).ready(function(){
$('#div_1').after('<div id="div_3">');
$('#div_2').before('</div>');
});
div_3 gets inserted after div_1 but with a closing tag i.e.
<div id="div_1"></div>
<div id="div_3"></div>
<strong>stuff here that always begins with same string but does not end that way</strong>
some text here with no consistent string
<div id="div_2"></div>