M
M
Mosapi2020-04-14 15:51:32
JavaScript
Mosapi, 2020-04-14 15:51:32

Why is the dom element not found by parameter from the array?

Good afternoon, I am writing an extension for chrome.
And everything works fine, except for one function.
content-script.js:

chrome.storage.local.get(['keys'], function(check){
mass = check.keys;
//mass = ['2443330','7579444','9581333','2609336','8612108','1617782','2600085'];
  var index;
  for(index = 0; index < mass.length; ++index){
    //console.log(mass[index]);
    let urlx = document.querySelectorAll('a[href$="'+mass[index]+'"]');//должна выбираться ссылка с атрибутом href заканчивающаяся на цифру из массива.
                console.log(urlx);
    for(var i = 0; i < urlx.length; i++) {
    var tb_str = urlx[i].parentElement.previousSibling;
    var tr_str = urlx[i].parentElement.parentElement;
    var chislo = tb_str.innerHTML; //92600863
    tr_str.querySelector('a[name="table_checkbox_'+chislo+'"]').checked = true;
    }
  }
});

For some reason, the search for the element does not work:
let urlx = document.querySelectorAll('a[href$="'+mass[index]+'"]');
and, accordingly, all further manipulations on the found objects. I see this in the console [ ], but why don't I understand?
Made an example here -> https://jsfiddle.net/3d40tym2/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dasha Tsiklauri, 2020-04-14
@Mosapi

because it's check.keysalready an array? and you put an array in an array mass = [check.keys]?
trymass = check.keys

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question