I am trying to create a script to manipulate the DOM in WordPress.
My problem is that when creating the variables they appear empty because my script loads before the elements exist.
How can I solve this?
I have this little test that although it says the element exists, when I check the variable in the console it returns 0.
Many thanks.
var el2 = jQuery(".slick-slide");
if (el2 > 0) {
console.log('element does NOT exist in DOM');
} else {
console.log('element exists in DOM');
}
2
Answers
In jQuery, you do this like
Try create variables when document is ready