Вопрос

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

Это было полезно?

Решение

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");

Другие советы

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/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top