How to find an element from a jQuery AJAX response with jQuery .find() method

If you are a jQuery luver, you must know how to use jQuery Post and Date functions.

Recently I’ve been working on a project, that involves this jQuery Get thingy like this:

$.get("somedirectory/somefile.html", function(data){
   var whatineed = $(data).find("#someelement").html();

But, unfortunately it did not work. If you are facing the same case as me, try to wrap that data variable parsed from jQuery Get with some div tag, like this:

var whatineed = $("<div>" + data + "</div>").find("#someelement").html();

I tried it and it worked.


Leave a Reply

Your email address will not be published. Required fields are marked *