I do userscript, which must first extract all the links by the selector, and then search only among the contents of these links, possibly changing the attributes in the found elements. Is it possible with every search not to extract all the links?

Example:

var links=document.querySelectorAll('a.some_class'); // здесь некоторые действия с атрибутами href //этот код мог бы быть решением, но не работает, как мне необходимо //селектор зависит от действий с переменной links, //то есть сразу использовать a.some_class[href$="some_href"] b нельзя links.querySelectorAll('a[href$="some_href"] b')[0].style.display='none'; //NodeList не имеет этого метода //по-другому //можно попробовать создать document fragment, у которого есть такой метод var fragment=document.createDocumentFragment(); for(var i=0; i<links.length; i++){ fragment.appendChild(links[i]); //ссылка удаляется со страницы, поэтому этот вариант тоже не подходит } 

You can, of course, just use the links loop, but this will be rather slow.

  • they answered you correctly on so (only it would seem to me that the filter would be more convenient than each) and so it happens - zb '10
  • @eicto SO solution is a loop. The method, of course, is useful, but in this case, in my opinion, it can only be used to check several attributes at once. Or am I wrong? - Im ieee
  • Well, operations with dom are also expensive, cloning there ... it's still not clear what is worse, all the same cycle you have on the top representatives, and the clone of all trees is zb '11
  • @eicto As I explained in the comments, the answer with cloning is no good anyway. Apparently, the loop is actually the only solution. - Im ieee

0