Answer the question
In order to leave comments, you need to log in
How to implement the Click() function on a dynamically created button?
Good day! Actually, in order:
1. I'm trying to write a script for a specific site that would run from the Chrome console
2. On this site, at an indefinite time, the necessary one is generated, I managed to catch it using get by class name (only the class and innerHTML), but clicking with the click() function does not work.
I understand that the whole problem is that this is a dynamic element and something needs to be done with it before clicking (), but what exactly needs to be done - there is no understanding :)
I apply what is already working (waiting for the element to appear and its Search):
let ButtonEnter;
let MyTimer = setInterval(function SearchMyButton() {
ButtonEnter = document.getElementsByClassName('EtoKnopka');
if (ButtonEnter[0] != null) {
ButtonEnter[0].click();
console.log('Кнопка найдена!');
clearInterval(MyTimer);
}
});
Answer the question
In order to leave comments, you need to log in
function eventFire(el, etype){
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
eventFire(document.querySelector('.EtoKnopka'), 'click');
document.querySelector()
document.querySelectorAll()
document.getElementsByClassName()
document.getElementById()
document.getElementsByTagName()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question