通过带有“:”(冒号)的属性选择元素

avi*_*i12 3 javascript css attributes

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

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

小智 7

逃脱:通过用双反斜杠它前面\\

document.querySelectorAll("[xml\\:space]")
Run Code Online (Sandbox Code Playgroud)

看到这个:

https://bugzilla.mozilla.org/show_bug.cgi?id=883044


Ted*_*ead 6

你需要逃避结肠

document.querySelectorAll('[xml\\3A space]')
Run Code Online (Sandbox Code Playgroud)

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