如何选择未被HTML标记包围但只是在<br>
标记之前和之后的文字?
我是用xpath做的:
.xpath('//br/following-sibling::text()|//br/preceding-sibling::text()')
答案 0 :(得分:2)
var text = "";
$("br").parent().contents().each(function(i) {
if(this.nodeName == "#text")
{
text += this.textContent;
}
});
alert(text);
---&GT;
<span>bla bla bl<br/>a bla...</span> --> bla bla bla bla...