Let\'s consider following html code:
Some text followed by a span element
and another text followed by a bold
var textBefore = $('span')[0].previousSibling.nodeValue;
I was looking for a solution to this, and was confused why I needed to map to an array. Context was not working for me. I finally figured out how to write it.
This is the most basic solution. Putting the [0] converts the element to an elementNode, which allows you to call the previousSibling code. There's no need to put it in an array using the map function unless it is more convenient.