why this wont work? in my case im using Amp-script, the log is success coming but does not really work example code:
<amp-script script="btn-obs" layout="responsive" height="300" width="300" >
<input class="load-more" id="btnloadmore" type="submit" value="TEST BTN" on="tap:formme.submit" tabindex="0" role="button">
</amp-script>
<script id="btn-obs" type="text/plain" target="amp-script">
const loadmore = document.querySelector('#btnloadmore');
loadmore.addEventListener("click", () => {
console.log("cliked");
});
var left;
var right;
var bottom;
var top;
window.addEventListener("scroll", function(event){
let target = loadmore;
target.getBoundingClientRectAsync().then(coords => {
left = coords.left;
top = coords.top;
bottom = coords.bottom;
right = coords.right;
});
const isInViewport = top >= 0 &&
left >= 0 &&
bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
right <= (window.innerWidth || document.documentElement.clientWidth);
if(isInViewport == true){
loadmore.click();
console.log("yes")
}
});
</script>
and i got error like:
[amp-script] Uncaught TypeError: Cannot read properties of undefined (reading 'click')