I am having issue waiting on a DOM element to load. I am trying to get the value in an HTML input. Here are the 2 methods that I used but they both did not work:
Option 1):
$(document).ready(function() {
var inputVal = $(".class-name tag-label");
if (inputVal != undefined && inputVal.innerText != undefined && inputVal.innerText != ""){
//do something
}
else{
//not to do something
}
});
Option 2):
$(".class-name tag-label").ready(function() {
var inputVal = $(".class-name tag-label");
if (inputVal != undefined && inputVal.innerText != undefined && inputVal.innerText != ""){
//do something
}
else{
//not to do something
}
});
However, after the page is loaded, and I do $(".class-name tag-label") and it's returning the proper element with a value in the console. Anything I did incorrectly?
Thanks for your comments. I realized that document was undefined, and was actually missing windows.load
window.addEventListener('load', (event) => {
var inputVal = $(".class-name tag-label");
if (inputVal != undefined && inputVal.innerText != undefined && inputVal.innerText != ""){
//do something
}
else{
//not to do something
}
});
This works for me ^