Let's consider following html code:
<p>
Some text followed by <span>a span element</span>
and another text followed by <b>a bold text</b>.
</p>
How can I get the text before the span
and b
elements using jQuery?
I tried $("span").prev()
and $("b").prev()
but it did work because the text is not an element. I also tried $("span").parent()
but it matched whole paragraph, while I want only a part of it.
Could you advise any solution? Thank you in advance :-)