user3836151
user3836151

Reputation: 231

get value of text between br using jquery text()

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

to get the p is easy

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

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.

Upvotes: 0

Views: 381

Answers (1)

antyrat
antyrat

Reputation: 27765

You can try to use nextSibling DOM property:

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

jsFiddle

Upvotes: 6

Related Questions