Wrap Last Element in Array
I have the following markup:
- <h2 class="pagetitle">Key Staff Profiles</h2>
I want to select the last bit of text, in this case "Profiles," and wrap it with a span. I have the following code.
- var title = $(".pagetitle").text().split(" ");
var lastEl = title[title.length-1];
$(lastEl).wrap("<span />");
The first two lines do what I want, but I can't the wrap to work. What am I doing wrong? Thanks