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

289
Vistas
How can I change the border color of a node from it's XPath?

I have the XPath of an element (eg //html/body/div[1]/div[2]). I want to fetch the element and change it's border colour.

I can fetch the node using

document.evaluate(xPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE).singleNodeValue

But I can't figure out what to do next...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're not too far off from it -- Since you have the node from the code provided, you just have to assign add the styling. One way is by using JavaScript to add the in-line styles, for example:


// Select the node
var myDiv = document.evaluate('//html/body/div[1]/div[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;

//Add the style in-line
myDiv.style.border = "1px solid red";

// Or you can define a CSS class and add it that way
// myDiv.classList.add("my-class-with-border");

Working example: https://codepen.io/scarabaeus/pen/wvPqMPK

about 4 years ago · Juan Pablo Isaza Denunciar
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