Skip to content
Advertisement

How to reach a html tag inside a using Java Script?

I’ve got a span tag which placed inside a div, like below:

JavaScript

I want to set a border for the span tag as the input tag is clicked and also don’t want to use any id in the span. I’ve tried the bellow ways:

1:

JavaScript

2:

JavaScript

but none of them worked correctly! So would anybody help?

Advertisement

Answer

I would suggest to use querySelector: const d = document.querySelector("#sss span");

And then you can add style: d.style.border = "thick solid #0000FF";

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement