I have a list of items inside a nested div with parent, grand parent and great grand parent div
s. The html code looks like this :
<div class="marketing">
<div class="module-surround">
<div class="module-content">
<div class="k2ItemsBlock">
<ul>
<li><div>4</div></li>
<li><div>5</div></li>
<li><div>6</div></li>
<li><div>7</div></li>
</ul>
</div>
</div>
</div>
</div>
I want to convert all the listed items to parent divs and use all the listed items to replace the great grand parent div, so that the overall code looks like this :
<div><div>4</div></div>
<div><div>5</div></div>
<div><div>6</div></div>
<div><div>7</div></div>
The on my logic, I have want to use jQuery to achieve this, and so far I am able to get all the elements into a listed item inside .K2ItemsBloc ul into a variable and replace div.marketing with the list, my jQuery code to do that looks like this
//1. Get all content in K2ItemsBlock ul into a variable called mlist
var mlist = $(".k2ItemsBlock ul").contents()
//2. Change all li HTML elements inside the variable mlist to div
//3. Replace div.marketing with the variable mlist
$(".marketing").replaceWith(mlist);
The above line of jQuery code without task #2 converts my original code to
<li><div>4</div></li>
<li><div>5</div></li>
<li><div>6</div></li>
<li><div>7</div></li>
What I can figure out now is the syntax to convert all the li elements inside the variable mlist before replace div.marketing with it.
Any suggestions or ideas?