tags:

views:

137

answers:

1

I am trying to retrieve an entire webpage using get() and filter() out a specific section. This works fine when the page only includes the section I want to filter but if I input the entire page then it does not work.

Example:

 $(document).ready(function() {
  $.get("source.html", function(data) {

   $(data).filter(".spad").appendTo("#loadArea");
  });   
 });

If source is:

<table class="spad" border="0" cellpadding="0" cellspacing="0"><thead><tr class="head"><th>&nbsp;</th><th class="sep">&nbsp;</th><th class="sep">&nbsp;</th><th id="h_a_5_0" colspan="2" class="sep">Length of day</th><th id="h_a_8_0" colspan="3" class="sep">Solar noon</th></tr><tr class="head"><th rowspan="2">Date</th><th class="sep" rowspan="2">Sunrise</th><th class="sep" rowspan="2">Sunset</th><th class="sep" rowspan="2">This day</th><th class="sep" rowspan="2">Difference</th><th class="sep" rowspan="2">Time</th><th class="sep" rowspan="2">Altitude</th><th class="sep NULL">Distance</th></tr><tr class="head"><th class="sep smaller">(10<sup>6</sup> km)</th></tr></thead><tbody><tr class="c0"><td>Mar 2, 2009</td><td>5:41 AM</td><td>6:19 PM</td><td>12h 37m 36s</td><td>&#8722; 1m 37s</td><td>12:00 Noon</td><td>69.7° </td><td>148.258</td></tr><tr class="c1"><td>Mar 3, 2009</td><td>5:42 AM</td><td>6:18 PM</td><td>12h 35m 58s</td><td>&#8722; 1m 37s</td><td>12:00 Noon</td><td>69.4° </td><td>148.294</td></tr><tr class="c0"><td>Mar 4, 2009</td><td>5:42 AM</td><td>6:17 PM</td><td>12h 34m 20s</td><td>&#8722; 1m 38s</td><td>12:00 Noon</td><td>69.0° </td><td>148.331</td></tr><tr class="c1"><td>Mar 5, 2009</td><td>5:43 AM</td><td>6:16 PM</td><td>12h 32m 42s</td><td>&#8722; 1m 38s</td><td>11:59 AM</td><td>68.6° </td><td>148.367</td></tr><tr class="c0"><td>Mar 6, 2009</td><td>5:43 AM</td><td>6:15 PM</td><td>12h 31m 03s</td><td>&#8722; 1m 38s</td><td>11:59 AM</td><td>68.2° </td><td>148.405</td></tr><tr class="c1"><td>Mar 7, 2009</td><td>5:44 AM</td><td>6:13 PM</td><td>12h 29m 25s</td><td>&#8722; 1m 38s</td><td>11:59 AM</td><td>67.8° </td><td>148.442</td></tr><tr class="c0"><td>Mar 8, 2009</td><td>5:45 AM</td><td>6:12 PM</td><td>12h 27m 46s</td><td>&#8722; 1m 38s</td><td>11:59 AM</td><td>67.4° </td><td>148.480</td></tr></tbody></table>

it works fine.

If i point the script at (or download it locally, this is not a cross domain ajax request thing) http://www.timeanddate.com/worldclock/astronomy.html?n=47 nothing shows up.

Any hints as to where I might be going wrong?

+2  A: 

You don't want filter(); filter() removes elements from the set that don't match the given expression. You want find():

$(data).find(".spad").appendTo("#loadArea");
Shog9