0

I am not able to reach to button tag from .li. How do I do it in JS?

    <div class="li">
        <li> Apple <button>Delete</button></li>
        <li> Ball <button>Delete</button></li>
        <li> Cat <button>Delete</button></li>
        <li> Dog <button>Delete</button></li>
    </div>

Is button a sibling or a child element of li tag? I get undefined in the console either way.

1
  • Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented Nov 10, 2022 at 9:36

1 Answer 1

0

You might want to query the parent div first, then get all buttons

let buttons = document.body.querySelector(".li").getElementsByTagName("button");

// test if we've queried the buttons successfully 
buttons[0].style.display = "none";

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.