1

Как исправить ошибку JS Uncaught TypeError: Cannot read property 'getElementsByTagName' of null?

jQuery(document).ready(function($) {
  const select2 = document.querySelector('#cf_wrapper_inner_custom_f_7_132').getElementsByTagName('option');
  for (let i = 0; i < select2.length; i++) {
    if (select2[i].textContent === 'Text1') select2[i].selected = true;
  }
  const select = document.querySelector('#cf_wrapper_inner_custom_f_4_132').getElementsByTagName('option');
  for (let i = 0; i < select.length; i++) {
    if (select[i].textContent === 'Text2;') select[i].selected = true;
  }
  const select1 = document.querySelector('#cf_wrapper_inner_custom_f_6_132').getElementsByTagName('option');
  for (let i = 0; i < select1.length; i++) {
    if (select1[i].textContent === 'Text3') select1[i].selected = true;
  }
});

1 ответ 1

1
jQuery(document).ready(function($) {
  $('#cf_wrapper_inner_custom_f_7_132').val('Text1');
  $('#cf_wrapper_inner_custom_f_4_132').val('Text2;'); // ; - needed?
  $('#cf_wrapper_inner_custom_f_6_132').val('Text3');
});

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

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