Saturday, 15 August 2015

javascript - Jquery/Json - How can I get the last in this JSON object? -



javascript - Jquery/Json - How can I get the last <P> in this JSON object? -

the usual .last or :last jquery selectors not doing me. have object content.object has html in

<p> item 1 </p> <p> item 2 </p> <p> item 3 </p>

i have tried

var lastitem = $(content.object).find('p:last');

and

var lastitem = $(content.object).find('p').last();

but these aren't doing trick , maintain getting errors. how can text in lastly

?

the find method wont work because within same depth p tags

if json object looks this

var content = { object: '<p>item 1</p><p>item 2</p><p>item 3</p>' };

you can access lastly p so:

var lastitem = $( content.object ).last();

javascript jquery json

No comments:

Post a Comment