3

For example in javascript using getelementbyid:

document.getElementById("theID").style.width="100%";

can i change the css from the node retrieved by xpath like with getelementbyid?

2
  • 1
    With XPath you can query XML, not change it. Commented Jan 25, 2013 at 1:23
  • There is no "XPath" here. Please consider posting a real example/intended usage. Also, it doesn't matter how an Element is found in the DOM (gEBI, CSS selectors, XPath): DOM Elements can be mutated, as what is done in the posted code. Commented Jan 25, 2013 at 2:23

2 Answers 2

4

Yes, i did it like this:

var xpath = 'your xpath';

var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

matchingElement.style.color = "blue";
Sign up to request clarification or add additional context in comments.

Comments

0

xpath= $x('//body'); // this will return an array usually containing 1 element

xpath[0].classList.value=""; // edit class name

xpath[0].style.display="none"; // edit style attributes

useful links I found: https://devhints.io/xpath#class-check

How can I change an element's class with JavaScript?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.