How come this works:
jQuery(this).closest("li").find("p").text();
But when I have it inside a function, it doesn't work:
jQuery.each(words, function(i, v) {
jQuery(this).closest("li").find("p").text();
});
Do I need to pass this
through the function?
Full Code:
jQuery(document).ready(function() {
jQuery('.js-trigger-editb').bind("mouseup", function() {
// find the p tag that contains the content and split it
var words = jQuery(this).closest("li").find("p").text().split(" ");
// wrap words in p tag into span tags
jQuery.each(words, function(i, v) {
jQuery(this).closest("li").find("p").append(jQuery("<span>").text(v));
});
});
});