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

275
Views
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 answers
Answer question

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 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!