Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
Can't programmatically add <line> element inside <g> element

I am trying to create a <line> element and append it to a <g> element. When I do it through HTML, it works:

    <svg>
      <g id="graph-paper">
        <line class="lineStyle" x1="0" y1="0" x2="100" y2="100"></line>
      </g>
    </svg>

    <style>
       .lineStyle {
         fill: none;
         shape-rendering: crispEdges;
         stroke: black;
         stroke-width: 1px;
       }
    </style>

But when I try to add it with javascript, it doesn't:

let graphPaper = document.getElementById("graph-paper")
let line = document.createElement("line")
line.setAttribute("x1", "0")
line.setAttribute("x2", "20")
line.setAttribute("y1", "40")
line.setAttribute("y2", "80")
line.setAttribute("class", "lineStyle")
graphPaper.appendChild(line)

What am I doing wrong? I want to do it with javascript.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda