tuna
tuna

Reputation: 6351

Getting content of a div includes the div itself in jquery

I have the following html template. I want to get the first person_line div's content includes the person_line div.

<div class=​"person_row">​
    <div class=​"row-fluid person_line">​
        <div class=​"span4">​…​</div>​
        <div class=​"span8">​…​</div>​
        <div class=​"clearfix">​</div>​
    </div>​
    <div class=​"row-fluid person_line">​
        <div class=​"span4">​…​</div>​
        <div class=​"span8">​…​</div>​
        <div class=​"clearfix">​</div>​
    </div>​
</div>​

I tried $($('.person_line')[0]).html() but that does not include the <div class=​"row-fluid person_line">. Any ideas ? How can i get the content of person_line as html which includes the upper div.

Upvotes: 1

Views: 467

Answers (2)

Akhilesh Sharma
Akhilesh Sharma

Reputation: 1628

Try this

$(".person_line").eq(0).html();

more over if you want to get the children of the person_row

childArray = $(".person_row").find(".person_line");

Hope this might help.

Upvotes: 0

Adil Shaikh
Adil Shaikh

Reputation: 44740

try using outerHTML -

$('.person_line')[0].outerHTML

Upvotes: 5

Related Questions