I'm having some issues using jquery to wrap an block around a tag, I think the biggest problem I am having is with the jquery selector, but I'm very new to jquery so I'm not sure where exactly the problem is.
I have the following html
<section class="flexslider shop">
<ul class="flex-direction-nav">
<li>
<a href="#" class="flex-prev">Previous</a>
</li>
<li>
<a href="#" class="flex-next">Next</a>
</li>
</ul>
</section>
I need to use jquery to wrap a tag around each tag and also insert a new li element between the two existing, the end result after the jquery has made its modifications should be the following:
<section class="flexslider shop">
<ul class="flex-direction-nav">
<li>
<i class="icon-circle-arrow-left">
<a href="#" class="flex-prev">Previous</a>
</i>
</li>
<li>
<i class="icon-zoom-in">
<a href="#" id="nav-zoom-in"></a>
</i>
</li>
<li>
<i class="icon-circle-arrow-right">
<a href="#" class="flex-next">Next</a>
</i>
</li>
</ul>
</section>
any help that could be given is greatly appreciated. I searched for hours but could not figure out how to get jquery of this complexity working. Also, all of this needs to happen once the page has loaded fully, there are no other triggers than that though.
Update
I now have it semi working with the help of some of you, this is what I have so far and it works as it should, the problem is the selectors in the jquery are not specific enough, and I can not modify the html as it is being generated by a jquery plugin, so I am attempting to modify that plugin after the fact by using this little script you all are helping me with, what I have so far is the following:
The script in question generates the following html:
<ul class="flex-direction-nav">
<li>
<a href="#" class="flex-prev">Previous</a>
</li>
<li>
<a href="#" class="flex-next">Next</a>
</li>
</ul>
I added the tag with a class in order to target it through jquery, so the html now looks as follows:
<section class="flexslider shop">
<ul class="flex-direction-nav">
<li>
<a href="#" class="flex-prev">Previous</a>
</li>
<li>
<a href="#" class="flex-next">Next</a>
</li>
</ul>
</section>
The jquery I'm using now is the following, and it does as needed, but is not specific enough since I have more than one slider on the page.
$(window).load(function() {
$(".flex-direction-nav li:last").before('<li><i class="icon-zoom-in"><a href="#" id="nav-zoom-in"></a></i></li>');
$(".flex-prev").wrap('<i class="icon-circle-arrow-left" />');
$(".flex-next").wrap('<i class="icon-circle-arrow-right" />');
});
This is now generating the proper html output and is working as it is supposed to, however I need it to specifically target the ul class="flex-direction-nav" that is inside of section class="flexslider shop" since there is more than one ul class="flex-direction-nav" on the page
iis a presentational markup. You should useem(emphasis) or (in your case) CSS..wrap,.addClassand.removeClassmethods.