使用jquery text()获取br之间的文本值 [英] get value of text between br using jquery text()

查看:572
本文介绍了使用jquery text()获取br之间的文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很难处理可怕的标记,它只是没有类看起来像这样:

It's hard to work on terrible markup, it just not don't have class it look something like this:

<p>p</p>
<br>br1
<br>br2
<br>br3

获得p很容易

console.log($('p').text());

但是如何获得位于 br 标签?如果可能的话我想在br之后检查是否有任何等于br1的值,如果是,则删除该行。使用attr()的想法仍然不知道怎么做。

but how to get the br1, br2 that located between br tag? if possible I want to check after br is there any value equal to br1, if yes then remove that line. Thought of use attr() still don't have idea how to do it.

推荐答案

你可以尝试使用 nextSibling DOM属性:

You can try to use nextSibling DOM property:

$( 'br' ).each( function() {
    console.log( $( this ).get( 0 ).nextSibling.nodeValue );
});

jsFiddle

这篇关于使用jquery text()获取br之间的文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆