Reputation: 35
In a Wordpress page I have a Wordpress plugin (Showoff) that loads DOM elements onto the page. I want to create a way to link to these DOM elements from outside that page using this code:
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
var gotoProduct = function gotoProduct() {
var productID = getUrlParameter('product');
var showoffInit = showoff().init;
if ($(productID).length) {$('.'+productID).click();}
}
but any link will be invalid unless all the DOM elements have been loaded. I tried various methods posted here but none seem to work for me. I think part of the problem might be that the code called by the plugin is called after the DOM is ready only.
So I need to find a way to wait for these DOM elements to finish loading before calling my function.
Any suggestions will be most welcome!
Upvotes: 2
Views: 193
Reputation: 206
You can try .load() method of jquery to check whether the DOM element is already loaded then call your method.
$(window).load(function() {
//perform required call
});
Hope this might help.
Upvotes: 1