0

i'm a new in programming jQuery. I want to parse an external html page and show it in a mobile app.

function mealSearch() {


$.get('http://www.web-page.de/page.html', function(html){
   html = $(html.replace(/<img[^>]*>/g,""));
   console.log((html));
});

I get the whole html page I want, without the pictures.

Now I want to get only the part which is in a special div?

When I add .find after the replace, I get an error: has no method find

Thanks for your help

krank42
  • 19
  • 4
  • Just curious, why did you unaccept my answer and then accept one that was made after and offers the same information as mine... but doesn't offer the alternative that you should really be using? If you don't use that alternative you are parsing the entire dom for `img` when you really only care about what is inside the specific `div` that you care about... also, if you have a dom you should parse it as a dom rather than as a string. – Smern Jun 02 '13 at 13:10

2 Answers2

1

Probably you are doing this -

html = $(html.replace(/<img[^>]*>/g,"").find("div.someclass"));

(you are getting that error bcoz you are trying to use .find() on string var and not on jQuery object)

You need to do this -

html = $(html.replace(/<img[^>]*>/g,"")).find("div.someclass");
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
0

html.replace() is a string, not a jquery object. I'm guessing (since you didn't post the code with the find and you stated that you added .find after replace) that you were doing this:

html = $(html.replace(/<img[^>]*>/g,"").find("#specialDiv"));

if that is the case, just move the find outside:

html = $(html.replace(/<img[^>]*>/g,"")).find("#specialDiv");

also, there really is no need to modify the dom as a string... nor do you need to worry about removing tags from content you don't care about... this would be better:

html = $(html).find("#specialDiv");
html.find("img").remove();

http://jsfiddle.net/S8zxQ/

Smern
  • 18,746
  • 21
  • 72
  • 90