How to get a text before given element using jQuery?

前端 未结 4 1364
鱼传尺愫
鱼传尺愫 2020-12-17 14:59

Let\'s consider following html code:

Some text followed by a span element and another text followed by a bold

4条回答
  •  無奈伤痛
    2020-12-17 15:19

    I have come up with a following solution:

    var c = $("span").context.previousSibling;
    alert(c.data);
    

    But I am not sure how safe it is when using different browsers?

提交回复
热议问题