Make sure to check out the jsfiddle demo linked below before proceeding:
I need to transform the original structure as shown below:
<div class="out">
<a>im here</a>
<a>to save</a>
<a>our</a>
<a>country</a>
</div>
into
<div class="newout">
<ul>
<li class="haha">
<a>im here</a>
<span><a>im here</a></span>
</li>
<li class="haha">
<a>to save</a>
<span><a>to save</a></span>
</li>
<li class="haha">
<a>our</a>
<span><a>our</a></span>
</li>
<li class="haha">
<a>country</a>
<span><a>country</a></span>
</li>
</ul>
</div>
This involves the following steps:
- 1. Clone the
a
tags - 2. Wrap them with
span
tags - 3. Append them to the previous
a
tags - 4. Wrap the previous tags in a
li
tag and add a class - 5. Wrap all the elements in a
ul
tag
I am struggling with implementing STEP 4 using JQuery. I am unsure of how to select the tags and add the necessary wrapping element.
Any help would be greatly appreciated!