I have referenced the following Q&A: First word selector
I am looking to use the same sort of <span></span>
setup, however, I would like for it to occur for every first word of every <p>
within a particular <div>
. How can I specify this?
$(window).load(function(){
(function () {
var node = $("p").contents().filter(function () { return this.nodeType == 3 }).first(),
text = node.text(),
first = text.slice(0,text.indexOf(" "));
if (!node.length)
return;
node[0].nodeValue = text.slice(first.length);
node.before('<span>' + first + '</span>');
})();
});
Within the stylesheet, I then can take the simple <span></span>
that's been applied to various selectors, and specify what the 'span' function will do with each selector.