2

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?

fpilee
  • 1,918
  • 2
  • 22
  • 38
  • With XPath you can query XML, not change it. – Kirill Polishchuk Jan 25 '13 at 01: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. –  Jan 25 '13 at 02:23

2 Answers2

3

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";
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?

SMAKSS
  • 9,606
  • 3
  • 19
  • 34