How can I load a collection of page elements (EG. <div class="myClass">
) from an external page into an array please?
Asked
Active
Viewed 834 times
-1

James Allardice
- 164,175
- 21
- 332
- 312

Strontium_99
- 1,771
- 6
- 31
- 52
-
Not enough details. See [FAQ](http://stackoverflow.com/faq). – Oybek Feb 07 '12 at 10:40
-
Sorry for not being totally clear with my question. I wish to load a collection of elements using jquery ajax into an array from an external page within the same domain. – Strontium_99 Feb 07 '12 at 10:46
2 Answers
2
Your question is very vague, but assuming you are using jQuery.get
to fire an AJAX request to a remote page:
$.get("somePage.html", function(data) {
var elems = $(data).filter(".myClass").get();
});
filter
is used to reduce the elements of data
to those matching the selector. get
returns a normal array (rather than a jQuery object).

James Allardice
- 164,175
- 21
- 332
- 312
-
Just what I was looking for. I was messing up the syntax. Thanks. – Strontium_99 Feb 07 '12 at 10:47
0
You cannot load elements from an external page in you script because that would be against the same origin policy. What you could do is using JSONP where I relate to this question: can jquery ajax call external webservice?

Community
- 1
- 1

mas-designs
- 7,498
- 1
- 31
- 56
-
Sorry. Yeah, this is not across domains. All the pages are hosted under the same domain. – Strontium_99 Feb 07 '12 at 10:44