jquery - get text of html return

ajax, dom, jquery

Solution

use `filter()` to find the text..

try this

$(msg).filter('div#x p').text(); //this  will give you hello

OR `find()`

 $(msg).find('div#x p').text();

Problem

This is probably simple but i can't seem to find my answer... i have an ajax call that returns html ``` dataType: "html" ``` and it's returned 'msg' looks like: ``` <div id="x"><p>Hello</p></div> ``` and that gets dom-added to the top of a parent div: ``` ajax call... request.done(function(msg) { $('#parent').prepend(msg); } ``` The issue is, i DONT want to do this dom manipulation if it's text hasn't changed (as there are other effects that take place that i've truncated out. (This is a notice display that checks for updates in an interval) so, what i want to do is find "Hello" within msg and compare it against a current div x's p that may already be on page. This second part is easy to address, but the first part, I need to do something like msg.text() to just get "Hello", but a few varities i tried failed. pointers?

Original source