通过带有& quot ::& quot;属性的元素来选择元素(冒号) [英] Select elements by attributes with ":" (colon)

查看:60
本文介绍了通过带有& quot ::& quot;属性的元素来选择元素(冒号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,有一种情况是库生成元素,而我需要从那里选择特定的元素-这些元素恰好包含带有:"的属性.
换句话说,我最终尝试使用以下代码进行选择: document.querySelectorAll("[xml:space]").
但是,当在Chrome中进行测试时,它不起作用,也无法使用 document.querySelectorAll("['xml:space']")选择-他们都抛出了 DOMException :
http://i.imgur.com/GrjpL85.png

In my project, there's a case where a library generates elements, and I need to select specific elements from there - which happen to contain an attribute with ":".
In other words, I ended up attempting to select using: document.querySelectorAll("[xml:space]").
But, when tested in Chrome, it didn't work, nor selecting using document.querySelectorAll("['xml:space']") - they both threw a DOMException:
http://i.imgur.com/GrjpL85.png

我的问题是,如何使上面的选择器返回具有 xml:space 属性的元素列表?
谢谢!

My question is, how to make the above selector return the list of the elements with xml:space attribute?
Thanks!

推荐答案

您需要逃脱冒号

document.querySelectorAll('[xml\\3A space]')

我使用 https://mothereff.in/css-escapes 来获取上面的代码:)

I used https://mothereff.in/css-escapes to get the code above :)

这篇关于通过带有& quot ::& quot;属性的元素来选择元素(冒号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆