Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting text between <br>

Is it possible to select text between
tags? I am working with the preformatted code below trying to select this data: New York, NY 10012

I've played around with $('#address').find('br').eq(2).text(), but know that there must be a better way.

    <div id="address">
        Joe Dirt<br>
        PO Box 842<br>
        New York NY 10012<br>
        800-555-5555<br>
        <br>
    </div>

Thanks!

like image 518
user2062244 Avatar asked Sep 20 '25 21:09

user2062244


1 Answers

Retrieve the HTML for the div and split on the br tag:

$.trim($("#address").html().split("<br>")[2]);

JS Fiddle: http://jsfiddle.net/KQgu5/

like image 200
Kevin Bowersox Avatar answered Sep 22 '25 11:09

Kevin Bowersox