Reputation: 805
I would like to modify the dom with jquery, but when I run the command, the dom element doesn't exist. Is it possible to wait for the other script to build the necessary html elements?
I tried with the 'live' function, but doesn't help.
jQuery(document).live('ready', function(){
var pressTitle;
jQuery('.press-page .soliloquy-item').each(function(){
pressTitle = jQuery(this).children().attr('title');
console.log(pressTitle);
});
});
How can I fix this?
Upvotes: 0
Views: 68
Reputation: 700442
You can check if you find any elements, and if you don't, wait for a while and try again:
function getTitle() {
var pressTitle;
var t = jQuery('.press-page .soliloquy-item');
if (t.length) {
t.each(function(){
pressTitle = jQuery(this).children().attr('title');
console.log(pressTitle);
});
} else {
window.setTimeout(getTitle, 100);
}
}
jQuery(document).ready(getTitle);
Upvotes: 2