javascript - 是否可以从 xpath 节点更改 css?

标签 javascript xpath

例如在 javascript 中使用 getelementbyid:

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

我可以像 getelementbyid 一样从 xpath 检索到的节点更改 css 吗?

最佳答案

是的,我是这样做的:

var xpath = 'your xpath';

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

matchingElement.style.color = "blue";

关于javascript - 是否可以从 xpath 节点更改 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14513422/

相关文章:

javascript - AsyncStorage React Native 保存数组

javascript - AngularJS 过滤在 1.5 版本中无法正常工作?

java - XPathFactory 不工作

php - 如果元素具有 xmlns 属性,则 Xpath 失败

javascript - XPath 表达式在求值器中运行良好,但在浏览器中运行不佳

javascript - 解析复杂的 JavaScript 表达式以将其重写为另一种格式

javascript - jQuery - 寻找一个特定的词

javascript - 如何使用 Jasmine 断言异常?

PHP - SimpleXML 故障排除中子节点中的命名空间转换

html - 基于多个子级的 XPath 父级