I’ve got a span
tag which placed inside a div
, like below:
JavaScript
x
5
1
<div onclick="doActiveCheckBox('color1')" id="sss" class="test form-check form-option form-check-inline mb-2">
2
<input class="test form-check-input" type="radio" name="color" id="color1" data-bs-label="colorOption" value="/تاریک" checked="">
3
<label class="form-option-label rounded-circle" for="color1"><span style="border:inherit; border-block-color:purple;" class="form-option-color rounded-circle" style="background-image: url(/img/ProductColors/green1.jpg)"></span></label>
4
</div>
5
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
1
3
1
var d=document.getElementById("sss").getElementsByTagName("span");
2
d.style.border = "thick solid #0000FF";
3
2:
JavaScript
1
5
1
var d=document.getElementById("sss").getElementsByClassName();
2
for (var i = 1; i <= d.length; i++) {
3
d[1].style.border = "thick solid #0000FF";
4
}
5
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";