Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
¿Cómo llegar a una etiqueta html <span> dentro de un <div> usando Java Script?

Tengo una etiqueta de span que se coloca dentro de un div , como a continuación:

 <div onclick="doActiveCheckBox('color1')" id="sss" class="test form-check form-option form-check-inline mb-2"> <input class="test form-check-input" type="radio" name="color" id="color1" data-bs-label="colorOption" value="/تاریک" checked=""> <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> </div>

Quiero establecer un border para la etiqueta de span cuando se hace clic en la etiqueta de input y tampoco quiero usar ninguna id en el span . He intentado las siguientes formas:

1:

 var d=document.getElementById("sss").getElementsByTagName("span"); d.style.border = "thick solid #0000FF";

2:

 var d=document.getElementById("sss").getElementsByClassName(); for (var i = 1; i <= d.length; i++) { d[1].style.border = "thick solid #0000FF"; }

¡pero ninguno de ellos funcionó correctamente! Entonces, ¿alguien ayudaría?

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

Yo sugeriría usar querySelector: const d = document.querySelector("#sss span");

Y luego puede agregar estilo: d.style.border = "thick solid #0000FF";

about 4 years ago · Santiago Gelvez Report

0

 var d=document.getElementById("sss").getElementsByTagName("span"); ^//returns an array d.get.style.border = "thick solid #0000FF";//d[0].style //┗━━┛

No hay una propiedad llamada get , así que acceda al primer elemento ya que getElementsByTagName devuelve una matriz.

about 4 years ago · Santiago Gelvez Report

0

Método Jquery si es necesario

 var span = $("#sss label span"); span.css("border", "thick solid #0000FF");

o si no está usando #sss solo las entradas (puede obtener múltiples resultados)

 var span = $("input.form-check label span");
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!