Home > front end >  Js querySelectorAll () to use child elements selector operators'> 'error, how to obtain
Js querySelectorAll () to use child elements selector operators'> 'error, how to obtain

Time:11-26

 & lt; ! DOCTYPE html> 

<meta charset="utf-8" & gt;
Title

<body>



<script>
Var ul=document. QuerySelector (' menu ');
//there are a lot of hierarchy, assuming that the menu under each recursive get ul li immediate child future generations under the immediate child of ul for processing
//Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document' : '& gt; Li> Ul 'is not a valid selector
//var subUl=document. QuerySelectorAll (' & gt; Li> Ul ');//connect to '& gt; 'symbol at the beginning, the error
//var subUl=document. QuerySelectorAll ('. Menu> Li> Ul ');//ok
HandleUl (ul);
The function handleUl (ul) {
//how to obtain direct child under ul li under the direct child elements ul set???????
Var subUls=ul. QuerySelectorAll (' & gt; Li> Ul ');//the error
SubUls. ForEach (function (item) {
//item do STH
//
The arguments. The callee (item);
});
}
</script>

CodePudding user response:

Top, nobody reply!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

Try
 
Var subUl=ul. QuerySelectorAll (' : the scope & gt; Li & gt; Ul ');

It is important to note that: the scope of the pseudo elements may have compatibility issues
  • Related