DiscordiaJQUERY - Using DIVs after load(ing) an external page
Before openning this thread, I googled this query during this night without success. It seems that it's a basic and common use of JQuery:
- load an external page (a table with
#IMGs
content) inside a (<DIV id="content"></DIV>
) - To access a specific ID : no problem using .live function
The problem is I want the list (Or array) of the IMGs#IDs
(newly) charged.
When I try:
var imgIDs = $('#content').find('img').开发者_开发百科map(function(){
return this.id;
}).get();
alert (imgIDs.length);
The alert always give me 0
! It's empty.
How could I proceed ?
Your description makes it sound like you're using .live
because you don't know when the content inside #content
has loaded. This is also a problem for the code example you give. You should run it from the success
(or maybe complete
) handler of the load. Eg. if you're using something like the following to populate the #content
div:
$('#content').load('/mydata');
Then try this to execute your function once it's been populated:
$('#content').load('/mydata', function() {
var imgIDs = $('#content').find('img').map(function(){
return this.id;
}).get();
alert(imgIDs.length);
});
See the jQuery load documentation on how this example works.
If you give a js fiddle or link demonstrating the 'real' problem, that'd help me be more sure about what you're asking.
精彩评论