How to get text before $ el using jQuery?
3 answers
This is not a pleasant solution, but it will work in this particular case:
$('#target_element').parent().text();
It is best to put this text in another element, such as a span. Otherwise, this text can be easily confused. If this were in between, you could do something like:
$('#target_element').prev().text();
Thus, you will encounter fewer errors.
EDIT
I found in another way :
var elementClone = $('#target_element').clone();
elementClone.children().remove();
elementClone.text();
+2