0

I have a website with many DIV elements without ID. The code of this website is created automatically with JavaScript, I can't change it. To change the z-index of selected elements without ID, I have to address them with JavaScript, with CSS it doesn't work.

How can I address children and grandchildren without ID using JavaScript?

I tried different functions but they do not work yet:

function huhu() {
  var x = document.getElementById("parent-element-with-id");
  x.querySelectorAll("*").style.zIndex = "9999";
}

function huhu() {
  document.querySelectorAll("#39 *").style.zIndex = "9999";
}

function huhu() {
  document.querySelectorAll("#39 > div > div).style.zIndex = "9999";
}

The JavaScript event:

<div onmouseover="huhu()"></div>

The working function:

function huhu() {
  document.getElementById("parent-element-with-id").style.zIndex = "9999";
}

The grandchild DIV without ID I want to address:

<div id="parent-element-with-id">
    <div>
      <div>
      </div>
    </div>
</div>

Besides, I also intend to address all * children and grandchildren. How can I achieve this?

Community
  • 1
  • 1
Till
  • 1
  • 2
  • 1
    Duplicate: [What do querySelectorAll and getElementsBy\* methods return?](https://stackoverflow.com/questions/10693845/what-do-queryselectorall-and-getelementsby-methods-return) –  Oct 13 '21 at 12:31
  • 1
    Please add a minimal reproducible code to debug. Post along with some HTML too. – Allan Jebaraj Oct 13 '21 at 12:31
  • 1
    Always check the browser console. Since the list of nodes returned by `querySelectorAll` has no style attribute, your code will result in errors. Press F12, check the console tab and google the errors. Also, always always always check the [docs](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll) first –  Oct 13 '21 at 12:32
  • 1
    the result of `querySelectorAll` is not one element, so you cannot apply style to it directly. – Kokodoko Oct 13 '21 at 12:33
  • The linked duplicate addresses the main logical problem with your functions. If your question is more about the _selectors_ , then please provide a sample of your HTML and we'll revisit your question. Please see [ask] and take the [tour]. – isherwood Oct 13 '21 at 12:45

0 Answers0