Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a selected div portion from a variable containing html code by using javascript?

I have a variable var 'html', it contains some html codes .in it there is a div with id messages. I want to get only that div contents from the 'html' variable into another variable using javascript.
Please help . .

like image 816
Francis Mv Avatar asked Dec 22 '11 11:12

Francis Mv


1 Answers

The easiest way with jQuery in my opinion:

var message = $('<div />').append(html).find('#message').text();
                                                      //.html();
like image 176
Felix Kling Avatar answered Sep 27 '22 15:09

Felix Kling