1

Имеется такой HTML-элемент

<button type="button" class="im-send-btn im-chat-input--send im-send-btn_static _im_send im-send-btn_send" aria-label="Отправить" data-tttype="2">Button </button>

Нужно при помощи JS осуществить клик по этой кнопке используя классы.

2 ответа 2

2

var elem = document.querySelector(
  '.im-send-btn.im-chat-input--send.im-send-btn_static._im_send.im-send-btn_send'
);

elem.onclick = function() {
  console.log('test');
}

elem.click();
<button type="button" class="im-send-btn im-chat-input--send im-send-btn_static _im_send im-send-btn_send" aria-label="Отправить" data-tttype="2">Button </button>

1

document.querySelector('.im-send-btn.im-chat-input--send.im-send-btn_static._im_send.im-send-btn_send').onclick = function() {
  console.log('Вы кликнули кнопку')
}
<button type="button" class="im-send-btn im-chat-input--send im-send-btn_static _im_send im-send-btn_send" aria-label="Отправить" data-tttype="2">Button </button>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.